From: Lukas Mai Date: Tue, 2 Mar 2010 20:36:53 +0000 (+0100) Subject: add import_into X-Git-Tag: v0.04~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=eeb7df5f00e383e8f4f4e9a364ea30f6d6edbf75;p=p5sagit%2FFunction-Parameters.git add import_into --- diff --git a/lib/Function/Parameters.pm b/lib/Function/Parameters.pm index fa117c4..9108695 100644 --- a/lib/Function/Parameters.pm +++ b/lib/Function/Parameters.pm @@ -36,23 +36,30 @@ sub _croak { goto &Carp::croak; } -sub import { - my $class = shift; +sub import_into { + my $victim = shift; my $keyword = @_ ? shift : 'fun'; - my $caller = guess_caller; - #warn "caller = $caller"; - _croak qq{"$_" is not exported by the $class module} for @_; + _croak qq["$_" is not exported by the ${\__PACKAGE__} module] for @_; $keyword =~ /^[[:alpha:]_]\w*\z/ or _croak qq{"$keyword" does not look like a valid identifier}; Devel::Declare->setup_for( - $caller, + $victim, { $keyword => { const => \&parser } } ); no strict 'refs'; - *{$caller . '::' . $keyword} = \&_fun; + *{$victim . '::' . $keyword} = \&_fun; +} + +sub import { + my $class = shift; + + my $caller = guess_caller; + #warn "caller = $caller"; + + import_into $caller, @_; } sub report_pos { @@ -320,13 +327,27 @@ so the parser knows the name (and possibly prototype) while it processes the body. Thus C really turns into C. +If you want to wrap C, you may find C +helpful. It lets you specify a target package for the syntax magic, as in: + + package Some::Wrapper; + use Function::Parameters (); + sub import { + my $caller = caller; + Function::Parameters::import_into $caller; + # or Function::Parameters::import_into $caller, 'other_keyword'; + } + +C is not exported by this module, so you have to use a fully +qualified name to call it. + =head1 AUTHOR Lukas Mai, C<< >> =head1 COPYRIGHT & LICENSE -Copyright 2009 Lukas Mai. +Copyright 2010 Lukas Mai. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published