* Moose
- Correct POD for builder to point to Recipe8, not 9. (gphat)
+ * Moose::Exporter
+ - When a nonexistent sub name is passed to as_is, with_caller, or
+ with_meta, throw a warning and skip the exporting, rather than
+ installing a broken sub. (doy)
+
0.89 Thu Aug 13, 2009
* Moose::Manual::Attributes
- Clarify "is", include discussion of "bare". (Sartak)
\&{ $package . '::' . $name };
};
+ if ( !defined(&$sub) ) {
+ Carp::cluck
+ "Trying to export undefined sub ${package}::${name}";
+ next;
+ }
+
my $fq_name = $package . '::' . $name;
$exports{$name} = $class->_make_wrapped_sub(
\&{ $package . '::' . $name };
};
+ if ( !defined(&$sub) ) {
+ Carp::cluck
+ "Trying to export undefined sub ${package}::${name}";
+ next;
+ }
+
my $fq_name = $package . '::' . $name;
$exports{$name} = $class->_make_wrapped_sub_with_meta(
}
for my $name ( @{ $args->{as_is} } ) {
- my $sub;
+ my ($sub, $coderef_name);
if ( ref $name ) {
$sub = $name;
# really want to keep these subs or not, we err on the
# safe side and leave them in.
my $coderef_pkg;
- ( $coderef_pkg, $name ) = Class::MOP::get_code_info($name);
+ ( $coderef_pkg, $coderef_name )
+ = Class::MOP::get_code_info($name);
- $is_removable{$name} = $coderef_pkg eq $package ? 1 : 0;
+ $is_removable{$coderef_name} = $coderef_pkg eq $package ? 1 : 0;
}
else {
$sub = do {
\&{ $package . '::' . $name };
};
+ if ( !defined(&$sub) ) {
+ Carp::cluck
+ "Trying to export undefined sub ${package}::${name}";
+ next;
+ }
+
$is_removable{$name} = 1;
+ $coderef_name = $name;
}
$export_recorder->{$sub} = 1;
- $exports{$name} = sub {$sub};
+ $exports{$coderef_name} = sub {$sub};
}
for my $name ( keys %{ $args->{groups} } ) {
BEGIN {
eval "use Test::Output;";
plan skip_all => "Test::Output is required for this test" if $@;
- plan tests => 47;
+ plan tests => 49;
}
ok( ! WantsSugar->can('with'), 'WantsSugar::with() has been cleaned' );
}
+{
+ package NonExistentExport;
+
+ use Moose ();
+
+ ::stderr_like {
+ Moose::Exporter->setup_import_methods(
+ also => ['Moose'],
+ with_caller => ['does_not_exist'],
+ );
+ } qr/^Trying to export undefined sub NonExistentExport::does_not_exist/,
+ "warns when a non-existent method is requested to be exported";
+}
+
+{
+ package WantsNonExistentExport;
+
+ NonExistentExport->import;
+
+ ::ok(!__PACKAGE__->can('does_not_exist'),
+ "undefined subs do not get exported");
+}