1 package Moose::Exporter;
7 use namespace::clean 0.08 ();
12 # 1 extra level because it's called by import so there's a layer
17 ( ref $_[1] && defined $_[1]->{into} ) ? $_[1]->{into}
18 : ( ref $_[1] && defined $_[1]->{into_level} )
19 ? caller( $offset + $_[1]->{into_level} )
24 sub build_import_methods {
28 my $exporting_package = caller();
30 $EXPORT_SPEC{$exporting_package} = \%args;
32 my ( $exporter, $exported )
33 = $class->_build_exporter( exporting_package => $exporting_package,
37 my $caller = Moose::Exporter->get_caller(@_);
39 # this works because both pragmas set $^H (see perldoc perlvar)
40 # which affects the current compilation - i.e. the file who use'd
41 # us - which is why we don't need to do anything special to make
42 # it affect that file rather than this one (which is already compiled)
47 # we should never export to main
48 if ( $caller eq 'main' ) {
50 qq{$exporting_package does not export its sugar to the 'main' package.\n};
54 if ( $exporting_package->can('_init_meta') ) {
55 $exporting_package->_init_meta(
57 %{ $args{init_meta_args} || {} }
64 # [12:24] <mst> yes. that's horrible. I know. but it should work.
66 # This will hopefully be replaced in the future once
67 # namespace::clean has an API for it.
69 @_ = ( 'namespace::clean', @{ $exported } );
71 goto &namespace::clean::import;
75 *{ $exporting_package . '::import' } = $import;
76 *{ $exporting_package . '::unimport' } = $unimport;
84 my $exporting_package = $args{exporting_package};
88 for my $name ( @{ $args{with_caller} } ) {
89 my $sub = do { no strict 'refs'; \&{ $exporting_package . '::' . $name } };
91 my $wrapped = Class::MOP::subname(
92 $exporting_package . '::' . $name => sub { $sub->( scalar caller(), @_ ) } );
94 $exports{$name} = sub { $wrapped };
96 push @exported_names, $name;
99 for my $name ( @{ $args{as_is} } ) {
104 $name = ( Class::MOP::get_code_info($name) )[1];
107 $sub = do { no strict 'refs'; \&{ $exporting_package . '::' . $name } };
109 push @exported_names, $name;
112 $exports{$name} = sub { $sub };
115 my $exporter = Sub::Exporter::build_exporter(
117 exports => \%exports,
118 groups => { default => [':all'] }
122 return $exporter, \@exported_names;