From: Dave Rolsky Date: Mon, 7 Sep 2009 17:07:04 +0000 (-0500) Subject: Move checking for sub existence and warning to a method of its own X-Git-Tag: 0.89_02~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0dd4228eeb2e49967b74638e9cab80beba103aea;p=gitmo%2FMoose.git Move checking for sub existence and warning to a method of its own --- diff --git a/lib/Moose/Exporter.pm b/lib/Moose/Exporter.pm index 26eaa11..492ec50 100644 --- a/lib/Moose/Exporter.pm +++ b/lib/Moose/Exporter.pm @@ -127,16 +127,8 @@ sub _make_sub_exporter_params { or die "The $package package does not use Moose::Exporter\n"; for my $name ( @{ $args->{with_meta} } ) { - my $sub = do { - no strict 'refs'; - \&{ $package . '::' . $name }; - }; - - if ( !defined(&$sub) ) { - Carp::cluck - "Trying to export undefined sub ${package}::${name}"; - next; - } + my $sub = $class->_sub_from_package( $package, $name ) + or next; my $fq_name = $package . '::' . $name; @@ -150,16 +142,8 @@ sub _make_sub_exporter_params { } for my $name ( @{ $args->{with_caller} } ) { - my $sub = do { - no strict 'refs'; - \&{ $package . '::' . $name }; - }; - - if ( !defined(&$sub) ) { - Carp::cluck - "Trying to export undefined sub ${package}::${name}"; - next; - } + my $sub = $class->_sub_from_package( $package, $name ) + or next; my $fq_name = $package . '::' . $name; @@ -195,16 +179,8 @@ sub _make_sub_exporter_params { $is_removable{$coderef_name} = $coderef_pkg eq $package ? 1 : 0; } else { - $sub = do { - no strict 'refs'; - \&{ $package . '::' . $name }; - }; - - if ( !defined(&$sub) ) { - Carp::cluck - "Trying to export undefined sub ${package}::${name}"; - next; - } + $sub = $class->_sub_from_package( $package, $name ) + or next; $is_removable{$name} = 1; $coderef_name = $name; @@ -219,6 +195,24 @@ sub _make_sub_exporter_params { return ( \%exports, \%is_removable ); } +sub _sub_from_package { + my $sclass = shift; + my $package = shift; + my $name = shift; + + my $sub = do { + no strict 'refs'; + \&{ $package . '::' . $name }; + }; + + return $sub if defined &$sub; + + Carp::cluck + "Trying to export undefined sub ${package}::${name}"; + + return; +} + our $CALLER; sub _make_wrapped_sub {