5 use parent qw(Exporter);
9 our @EXPORT_OK = qw(_hashify);
14 croak "Invalid number of entries to keep" if 0 > $keep;
16 return @_[0..scalar(@_) - 1] if $keep >= scalar(@_);
17 return ($keep ? @_[0..$keep - 1] : (),
18 ((1 + $keep) == scalar(@_)) && ((ref($_[$keep]) || '') eq 'HASH') ? %{ $_[$keep] } : @_[$keep..scalar(@_) - 1]);
30 SL::Util - Assorted utility functions
34 Most important things first:
36 DO NOT USE C<@EXPORT> HERE! Only C<@EXPORT_OK> is allowed!
42 =item C<_hashify $num, @args>
44 Hashifies the very last argument. Returns a list consisting of two
47 The first part are the first C<$num> elements of C<@args>.
49 The second part depends on the remaining arguments. If exactly one
50 argument remains and is a hash reference then its dereferenced
51 elements will be used. Otherwise the remaining elements of C<@args>
52 will be returned as-is.
54 Useful if you want to write code that can be called from Perl code and
55 Template code both. Example:
57 use SL::Util qw(_hashify);
60 my ($self, %params) = _hashify(1, @_);
61 # Now do stuff, obviously!
72 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>