1 package Mouse::Exporter;
6 use Scalar::Util qw(looks_like_number);
8 use Mouse::Util qw(not_supported);
14 my $class = $args{for_class}
15 or confess("Cannot call init_meta without specifying a for_class");
16 my $base_class = $args{base_class} || 'Mouse::Object';
17 my $metaclass = $args{metaclass} || 'Mouse::Meta::Class';
19 confess("The Metaclass $metaclass must be a subclass of Mouse::Meta::Class.")
20 unless $metaclass->isa('Mouse::Meta::Class');
22 # make a subtype for each Mouse class
23 Mouse::Util::TypeConstraints::class_type($class)
24 unless Mouse::Util::TypeConstraints::find_type_constraint($class);
26 my $meta = $metaclass->initialize($class);
28 $meta->add_method(meta => sub{
29 return $metaclass->initialize(ref($_[0]) || $_[0]);
32 $meta->superclasses($base_class)
33 unless $meta->superclasses;
39 my($class, $spec, @args) = @_;
44 foreach my $arg(@args){
45 if(ref $arg){ # e.g. use Mouse { into => $package };
48 elsif($arg =~ s/^[-:]//){
49 my $group = $spec->{group}{$arg} or confess(qq{group "$arg" is not exported by the $class module});
50 push @exports, @{$group};
57 my $into = $command->{into} || caller(($command->{into_level} || 0) + 1);
62 if($into eq 'main' && !$spec->{_not_export_to_main}){
63 warn qq{$class does not export its sugar to the 'main' package.\n};
71 my $exports_ref = @exports ? \@exports : $spec->{default};
73 foreach my $keyword(@{$exports_ref}){
75 *{$caller.'::'.$keyword} = $spec->{exports}{$keyword}
76 or confess(qq{"$keyword" is not exported by the $class module};
89 for my $keyword (@EXPORT) {
91 if(exists $is_removable{$keyword}
92 && ($code = $caller->can($keyword))
93 && (Mouse::Util::get_code_info($code))[0] eq __PACKAGE__){
95 delete $stash->{$keyword};
106 Mouse - The Mouse Exporter
113 Mouse::Exporter->setup_import_methods(
126 Goro Fuji (gfx) C<< <gfuji at cpan.org> >>