From: Lukas Mai Date: Sun, 28 Feb 2010 22:26:21 +0000 (+0100) Subject: check import list; default to 'fun'; documentation X-Git-Tag: v0.04~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FFunction-Parameters.git;a=commitdiff_plain;h=c9a39f6b949fddd97e099cbb562d16bac7360feb check import list; default to 'fun'; documentation --- diff --git a/lib/Function/Parameters.pm b/lib/Function/Parameters.pm index 78eb696..fa117c4 100644 --- a/lib/Function/Parameters.pm +++ b/lib/Function/Parameters.pm @@ -27,11 +27,24 @@ sub guess_caller { sub _fun ($) { $_[0] } +sub _croak { + require Carp; + { + no warnings qw(redefine); + *_croak = \&Carp::croak; + } + goto &Carp::croak; +} + sub import { my $class = shift; - my $keyword = shift; + my $keyword = @_ ? shift : 'fun'; my $caller = guess_caller; #warn "caller = $caller"; + + _croak qq{"$_" is not exported by the $class module} for @_; + + $keyword =~ /^[[:alpha:]_]\w*\z/ or _croak qq{"$keyword" does not look like a valid identifier}; Devel::Declare->setup_for( $caller, @@ -255,6 +268,9 @@ Function::Parameters - subroutine definitions with parameter lists print "$_\n" for mymap { $_ * 2 } 1 .. 4; + use Function::Parameters 'proc'; + my $f = proc ($x) { $x * 2 }; + =head1 DESCRIPTION This module lets you use parameter lists in your subroutines. Thanks to @@ -279,6 +295,10 @@ copied into C and initialized from L<@_|perlvar/"@_">. =head2 Advanced stuff +You can change the name of the new keyword from C to anything you want by +specifying it in the import list, i.e. C lets +you write C instead of C. + If you need L, you can put them after the parameter list with their usual syntax. There's one exception, though: you can only use one colon (to start the attribute list);