Ignore .c in xs dir
[gitmo/Moose.git] / lib / Moose / Exporter.pm
1 package Moose::Exporter;
2
3 use strict;
4 use warnings;
5
6 our $AUTHORITY = 'cpan:STEVAN';
7
8 use Class::MOP;
9 use List::MoreUtils qw( first_index uniq );
10 use Moose::Util::MetaRole;
11 use Scalar::Util qw(reftype);
12 use Sub::Exporter 0.980;
13 use Sub::Name qw(subname);
14
15 use XSLoader;
16
17 XSLoader::load( 'Moose', $XS_VERSION );
18
19 my %EXPORT_SPEC;
20
21 sub setup_import_methods {
22     my ( $class, %args ) = @_;
23
24     my $exporting_package = $args{exporting_package} ||= caller();
25
26     $class->build_import_methods(
27         %args,
28         install => [qw(import unimport init_meta)]
29     );
30 }
31
32 sub build_import_methods {
33     my ( $class, %args ) = @_;
34
35     my $exporting_package = $args{exporting_package} ||= caller();
36
37     $EXPORT_SPEC{$exporting_package} = \%args;
38
39     my @exports_from = $class->_follow_also($exporting_package);
40
41     my $export_recorder = {};
42     my $is_reexport     = {};
43
44     my $exports = $class->_make_sub_exporter_params(
45         [ @exports_from, $exporting_package ],
46         $export_recorder,
47         $is_reexport,
48     );
49
50     my $exporter = $class->_make_exporter($exports, $is_reexport);
51
52     my %methods;
53     $methods{import} = $class->_make_import_sub(
54         $exporting_package,
55         $exporter,
56         \@exports_from,
57         $is_reexport
58     );
59
60     $methods{unimport} = $class->_make_unimport_sub(
61         $exporting_package,
62         $exports,
63         $export_recorder,
64         $is_reexport
65     );
66
67     $methods{init_meta} = $class->_make_init_meta(
68         $exporting_package,
69         \%args
70     );
71
72     my $package = Class::MOP::Package->initialize($exporting_package);
73     for my $to_install ( @{ $args{install} || [] } ) {
74         my $symbol = '&' . $to_install;
75         next
76             unless $methods{$to_install}
77                 && !$package->has_package_symbol($symbol);
78         $package->add_package_symbol( $symbol, $methods{$to_install} );
79     }
80
81     return ( $methods{import}, $methods{unimport}, $methods{init_meta} );
82 }
83
84 sub _make_exporter {
85     my ($class, $exports, $is_reexport) = @_;
86
87     return Sub::Exporter::build_exporter(
88         {
89             exports   => $exports,
90             groups    => { default => [':all'] },
91             installer => sub {
92                 my ($arg, $to_export) = @_;
93                 my $meta = Class::MOP::class_of($arg->{into});
94
95                 goto &Sub::Exporter::default_installer unless $meta;
96
97                 # don't overwrite existing symbols with our magically flagged
98                 # version of it if we would install the same sub that's already
99                 # in the importer
100
101                 my @filtered_to_export;
102                 my %installed;
103                 for (my $i = 0; $i < @{ $to_export }; $i += 2) {
104                     my ($as, $cv) = @{ $to_export }[$i, $i + 1];
105
106                     next if !ref($as)
107                          && $meta->has_package_symbol('&' . $as)
108                          && $meta->get_package_symbol('&' . $as) == $cv;
109
110                     push @filtered_to_export, $as, $cv;
111                     $installed{$as} = 1 unless ref $as;
112                 }
113
114                 Sub::Exporter::default_installer($arg, \@filtered_to_export);
115
116                 for my $name ( keys %{$is_reexport} ) {
117                     no strict 'refs';
118                     no warnings 'once';
119                     next unless exists $installed{$name};
120                     _flag_as_reexport( \*{ join q{::}, $arg->{into}, $name } );
121                 }
122             },
123         }
124     );
125 }
126
127 {
128     my $seen = {};
129
130     sub _follow_also {
131         my $class             = shift;
132         my $exporting_package = shift;
133
134         local %$seen = ( $exporting_package => 1 );
135
136         return uniq( _follow_also_real($exporting_package) );
137     }
138
139     sub _follow_also_real {
140         my $exporting_package = shift;
141
142         if ( !exists $EXPORT_SPEC{$exporting_package} ) {
143             my $loaded = Class::MOP::is_class_loaded($exporting_package);
144
145             die "Package in also ($exporting_package) does not seem to "
146                 . "use Moose::Exporter"
147                 . ( $loaded ? "" : " (is it loaded?)" );
148         }
149
150         my $also = $EXPORT_SPEC{$exporting_package}{also};
151
152         return unless defined $also;
153
154         my @also = ref $also ? @{$also} : $also;
155
156         for my $package (@also) {
157             die
158                 "Circular reference in 'also' parameter to Moose::Exporter between $exporting_package and $package"
159                 if $seen->{$package};
160
161             $seen->{$package} = 1;
162         }
163
164         return @also, map { _follow_also_real($_) } @also;
165     }
166 }
167
168 sub _parse_trait_aliases {
169     my $class   = shift;
170     my ($package, $aliases) = @_;
171
172     my @ret;
173     for my $alias (@$aliases) {
174         my $name;
175         if (ref($alias)) {
176             reftype($alias) eq 'ARRAY'
177                 or Moose->throw_error(reftype($alias) . " references are not "
178                                     . "valid arguments to the 'trait_aliases' "
179                                     . "option");
180
181             ($alias, $name) = @$alias;
182         }
183         else {
184             ($name = $alias) =~ s/.*:://;
185         }
186         push @ret, subname "${package}::${name}" => sub () { $alias };
187     }
188
189     return @ret;
190 }
191
192 sub _make_sub_exporter_params {
193     my $class           = shift;
194     my $packages        = shift;
195     my $export_recorder = shift;
196     my $is_reexport  = shift;
197
198     my %exports;
199
200     for my $package ( @{$packages} ) {
201         my $args = $EXPORT_SPEC{$package}
202             or die "The $package package does not use Moose::Exporter\n";
203
204         for my $name ( @{ $args->{with_meta} } ) {
205             my $sub = $class->_sub_from_package( $package, $name )
206                 or next;
207
208             my $fq_name = $package . '::' . $name;
209
210             $exports{$name} = $class->_make_wrapped_sub_with_meta(
211                 $fq_name,
212                 $sub,
213                 $export_recorder,
214             );
215         }
216
217         for my $name ( @{ $args->{with_caller} } ) {
218             my $sub = $class->_sub_from_package( $package, $name )
219                 or next;
220
221             my $fq_name = $package . '::' . $name;
222
223             $exports{$name} = $class->_make_wrapped_sub(
224                 $fq_name,
225                 $sub,
226                 $export_recorder,
227             );
228         }
229
230         my @extra_exports = $class->_parse_trait_aliases(
231             $package, $args->{trait_aliases},
232         );
233         for my $name ( @{ $args->{as_is} }, @extra_exports ) {
234             my ( $sub, $coderef_name );
235
236             if ( ref $name ) {
237                 $sub = $name;
238
239                 my $coderef_pkg;
240                 ( $coderef_pkg, $coderef_name )
241                     = Class::MOP::get_code_info($name);
242
243                 if ( $coderef_pkg ne $package ) {
244                     $is_reexport->{$coderef_name} = 1;
245                 }
246             }
247             else {
248                 $sub = $class->_sub_from_package( $package, $name )
249                     or next;
250
251                 $coderef_name = $name;
252             }
253
254             $export_recorder->{$sub} = 1;
255
256             $exports{$coderef_name} = sub {$sub};
257         }
258     }
259
260     return \%exports;
261 }
262
263 sub _sub_from_package {
264     my $sclass  = shift;
265     my $package = shift;
266     my $name    = shift;
267
268     my $sub = do {
269         no strict 'refs';
270         \&{ $package . '::' . $name };
271     };
272
273     return $sub if defined &$sub;
274
275     Carp::cluck "Trying to export undefined sub ${package}::${name}";
276
277     return;
278 }
279
280 our $CALLER;
281
282 sub _make_wrapped_sub {
283     my $self            = shift;
284     my $fq_name         = shift;
285     my $sub             = shift;
286     my $export_recorder = shift;
287
288     # We need to set the package at import time, so that when
289     # package Foo imports has(), we capture "Foo" as the
290     # package. This lets other packages call Foo::has() and get
291     # the right package. This is done for backwards compatibility
292     # with existing production code, not because this is a good
293     # idea ;)
294     return sub {
295         my $caller = $CALLER;
296
297         my $wrapper = $self->_curry_wrapper( $sub, $fq_name, $caller );
298
299         my $sub = subname( $fq_name => $wrapper );
300
301         $export_recorder->{$sub} = 1;
302
303         return $sub;
304     };
305 }
306
307 sub _make_wrapped_sub_with_meta {
308     my $self            = shift;
309     my $fq_name         = shift;
310     my $sub             = shift;
311     my $export_recorder = shift;
312
313     return sub {
314         my $caller = $CALLER;
315
316         my $wrapper = $self->_late_curry_wrapper(
317             $sub, $fq_name,
318             sub { Class::MOP::class_of(shift) } => $caller
319         );
320
321         my $sub = subname( $fq_name => $wrapper );
322
323         $export_recorder->{$sub} = 1;
324
325         return $sub;
326     };
327 }
328
329 sub _curry_wrapper {
330     my $class   = shift;
331     my $sub     = shift;
332     my $fq_name = shift;
333     my @extra   = @_;
334
335     my $wrapper = sub { $sub->( @extra, @_ ) };
336     if ( my $proto = prototype $sub ) {
337
338         # XXX - Perl's prototype sucks. Use & to make set_prototype
339         # ignore the fact that we're passing "private variables"
340         &Scalar::Util::set_prototype( $wrapper, $proto );
341     }
342     return $wrapper;
343 }
344
345 sub _late_curry_wrapper {
346     my $class   = shift;
347     my $sub     = shift;
348     my $fq_name = shift;
349     my $extra   = shift;
350     my @ex_args = @_;
351
352     my $wrapper = sub {
353
354         # resolve curried arguments at runtime via this closure
355         my @curry = ( $extra->(@ex_args) );
356         return $sub->( @curry, @_ );
357     };
358
359     if ( my $proto = prototype $sub ) {
360
361         # XXX - Perl's prototype sucks. Use & to make set_prototype
362         # ignore the fact that we're passing "private variables"
363         &Scalar::Util::set_prototype( $wrapper, $proto );
364     }
365     return $wrapper;
366 }
367
368 sub _make_import_sub {
369     shift;
370     my $exporting_package = shift;
371     my $exporter          = shift;
372     my $exports_from      = shift;
373     my $is_reexport    = shift;
374
375     return sub {
376
377         # I think we could use Sub::Exporter's collector feature
378         # to do this, but that would be rather gross, since that
379         # feature isn't really designed to return a value to the
380         # caller of the exporter sub.
381         #
382         # Also, this makes sure we preserve backwards compat for
383         # _get_caller, so it always sees the arguments in the
384         # expected order.
385         my $traits;
386         ( $traits, @_ ) = _strip_traits(@_);
387
388         my $metaclass;
389         ( $metaclass, @_ ) = _strip_metaclass(@_);
390         $metaclass
391             = Moose::Util::resolve_metaclass_alias( 'Class' => $metaclass )
392             if defined $metaclass && length $metaclass;
393
394         my $meta_name;
395         ( $meta_name, @_ ) = _strip_meta_name(@_);
396
397         # Normally we could look at $_[0], but in some weird cases
398         # (involving goto &Moose::import), $_[0] ends as something
399         # else (like Squirrel).
400         my $class = $exporting_package;
401
402         $CALLER = _get_caller(@_);
403
404         # this works because both pragmas set $^H (see perldoc
405         # perlvar) which affects the current compilation -
406         # i.e. the file who use'd us - which is why we don't need
407         # to do anything special to make it affect that file
408         # rather than this one (which is already compiled)
409
410         strict->import;
411         warnings->import;
412
413         my $did_init_meta;
414         for my $c ( grep { $_->can('init_meta') } $class, @{$exports_from} ) {
415
416             # init_meta can apply a role, which when loaded uses
417             # Moose::Exporter, which in turn sets $CALLER, so we need
418             # to protect against that.
419             local $CALLER = $CALLER;
420             $c->init_meta(
421                 for_class => $CALLER,
422                 metaclass => $metaclass,
423                 meta_name => $meta_name,
424             );
425             $did_init_meta = 1;
426         }
427
428         if ( $did_init_meta && @{$traits} ) {
429
430             # The traits will use Moose::Role, which in turn uses
431             # Moose::Exporter, which in turn sets $CALLER, so we need
432             # to protect against that.
433             local $CALLER = $CALLER;
434             _apply_meta_traits( $CALLER, $traits );
435         }
436         elsif ( @{$traits} ) {
437             require Moose;
438             Moose->throw_error(
439                 "Cannot provide traits when $class does not have an init_meta() method"
440             );
441         }
442
443         my ( undef, @args ) = @_;
444         my $extra = shift @args if ref $args[0] eq 'HASH';
445
446         $extra ||= {};
447         if ( !$extra->{into} ) {
448             $extra->{into_level} ||= 0;
449             $extra->{into_level}++;
450         }
451
452         $class->$exporter( $extra, @args );
453     };
454 }
455
456 sub _strip_traits {
457     my $idx = first_index { ( $_ || '' ) eq '-traits' } @_;
458
459     return ( [], @_ ) unless $idx >= 0 && $#_ >= $idx + 1;
460
461     my $traits = $_[ $idx + 1 ];
462
463     splice @_, $idx, 2;
464
465     $traits = [$traits] unless ref $traits;
466
467     return ( $traits, @_ );
468 }
469
470 sub _strip_metaclass {
471     my $idx = first_index { ( $_ || '' ) eq '-metaclass' } @_;
472
473     return ( undef, @_ ) unless $idx >= 0 && $#_ >= $idx + 1;
474
475     my $metaclass = $_[ $idx + 1 ];
476
477     splice @_, $idx, 2;
478
479     return ( $metaclass, @_ );
480 }
481
482 sub _strip_meta_name {
483     my $idx = first_index { ( $_ || '' ) eq '-meta_name' } @_;
484
485     return ( 'meta', @_ ) unless $idx >= 0 && $#_ >= $idx + 1;
486
487     my $meta_name = $_[ $idx + 1 ];
488
489     splice @_, $idx, 2;
490
491     return ( $meta_name, @_ );
492 }
493
494 sub _apply_meta_traits {
495     my ( $class, $traits ) = @_;
496
497     return unless @{$traits};
498
499     my $meta = Class::MOP::class_of($class);
500
501     my $type = ( split /::/, ref $meta )[-1]
502         or Moose->throw_error(
503         'Cannot determine metaclass type for trait application . Meta isa '
504             . ref $meta );
505
506     my @resolved_traits = map {
507         ref $_
508             ? $_
509             : Moose::Util::resolve_metatrait_alias( $type => $_ )
510     } @$traits;
511
512     return unless @resolved_traits;
513
514     my %args = ( for => $class );
515
516     if ( $meta->isa('Moose::Meta::Role') ) {
517         $args{role_metaroles} = { role => \@resolved_traits };
518     }
519     else {
520         $args{class_metaroles} = { class => \@resolved_traits };
521     }
522
523     Moose::Util::MetaRole::apply_metaroles(%args);
524 }
525
526 sub _get_caller {
527
528     # 1 extra level because it's called by import so there's a layer
529     # of indirection
530     my $offset = 1;
531
532     return
533           ( ref $_[1] && defined $_[1]->{into} ) ? $_[1]->{into}
534         : ( ref $_[1] && defined $_[1]->{into_level} )
535         ? caller( $offset + $_[1]->{into_level} )
536         : caller($offset);
537 }
538
539 sub _make_unimport_sub {
540     shift;
541     my $exporting_package = shift;
542     my $exports           = shift;
543     my $export_recorder   = shift;
544     my $is_reexport    = shift;
545
546     return sub {
547         my $caller = scalar caller();
548         Moose::Exporter->_remove_keywords(
549             $caller,
550             [ keys %{$exports} ],
551             $export_recorder,
552             $is_reexport,
553         );
554     };
555 }
556
557 sub _remove_keywords {
558     shift;
559     my $package          = shift;
560     my $keywords         = shift;
561     my $recorded_exports = shift;
562     my $is_reexport   = shift;
563
564     no strict 'refs';
565
566     foreach my $name ( @{$keywords} ) {
567         if ( defined &{ $package . '::' . $name } ) {
568             my $sub = \&{ $package . '::' . $name };
569
570             # make sure it is from us
571             next unless $recorded_exports->{$sub};
572
573             if ( $is_reexport->{$name} ) {
574                 no strict 'refs';
575                 next
576                     unless _export_is_flagged(
577                             \*{ join q{::} => $package, $name } );
578             }
579
580             # and if it is from us, then undef the slot
581             delete ${ $package . '::' }{$name};
582         }
583     }
584 }
585
586 sub _make_init_meta {
587     shift;
588     my $class = shift;
589     my $args  = shift;
590
591     my %old_style_roles;
592     for my $role (
593         map {"${_}_roles"}
594         qw(
595         metaclass
596         attribute_metaclass
597         method_metaclass
598         wrapped_method_metaclass
599         instance_metaclass
600         constructor_class
601         destructor_class
602         error_class
603         )
604         ) {
605         $old_style_roles{$role} = $args->{$role}
606             if exists $args->{$role};
607     }
608
609     my %base_class_roles;
610     %base_class_roles = ( roles => $args->{base_class_roles} )
611         if exists $args->{base_class_roles};
612
613     my %new_style_roles = map { $_ => $args->{$_} }
614         grep { exists $args->{$_} } qw( class_metaroles role_metaroles );
615
616     return unless %new_style_roles || %old_style_roles || %base_class_roles;
617
618     return sub {
619         shift;
620         my %options = @_;
621
622         return unless Class::MOP::class_of( $options{for_class} );
623
624         if ( %new_style_roles || %old_style_roles ) {
625             Moose::Util::MetaRole::apply_metaroles(
626                 for => $options{for_class},
627                 %new_style_roles,
628                 %old_style_roles,
629             );
630         }
631
632         Moose::Util::MetaRole::apply_base_class_roles(
633             for_class => $options{for_class},
634             %base_class_roles,
635             )
636             if Class::MOP::class_of( $options{for_class} )
637                 ->isa('Moose::Meta::Class');
638
639         return Class::MOP::class_of( $options{for_class} );
640     };
641 }
642
643 sub import {
644     strict->import;
645     warnings->import;
646 }
647
648 1;
649
650 # ABSTRACT: make an import() and unimport() just like Moose.pm
651
652 __END__
653
654 =head1 SYNOPSIS
655
656   package MyApp::Moose;
657
658   use Moose ();
659   use Moose::Exporter;
660
661   Moose::Exporter->setup_import_methods(
662       with_meta => [ 'has_rw', 'sugar2' ],
663       as_is     => [ 'sugar3', \&Some::Random::thing ],
664       also      => 'Moose',
665   );
666
667   sub has_rw {
668       my ( $meta, $name, %options ) = @_;
669       $meta->add_attribute(
670           $name,
671           is => 'rw',
672           %options,
673       );
674   }
675
676   # then later ...
677   package MyApp::User;
678
679   use MyApp::Moose;
680
681   has 'name';
682   has_rw 'size';
683   thing;
684
685   no MyApp::Moose;
686
687 =head1 DESCRIPTION
688
689 This module encapsulates the exporting of sugar functions in a
690 C<Moose.pm>-like manner. It does this by building custom C<import>,
691 C<unimport>, and C<init_meta> methods for your module, based on a spec you
692 provide.
693
694 It also lets you "stack" Moose-alike modules so you can export Moose's sugar
695 as well as your own, along with sugar from any random C<MooseX> module, as
696 long as they all use C<Moose::Exporter>. This feature exists to let you bundle
697 a set of MooseX modules into a policy module that developers can use directly
698 instead of using Moose itself.
699
700 To simplify writing exporter modules, C<Moose::Exporter> also imports
701 C<strict> and C<warnings> into your exporter module, as well as into
702 modules that use it.
703
704 =head1 METHODS
705
706 This module provides two public methods:
707
708 =over 4
709
710 =item  B<< Moose::Exporter->setup_import_methods(...) >>
711
712 When you call this method, C<Moose::Exporter> builds custom C<import>,
713 C<unimport>, and C<init_meta> methods for your module. The C<import> method
714 will export the functions you specify, and can also re-export functions
715 exported by some other module (like C<Moose.pm>).
716
717 The C<unimport> method cleans the caller's namespace of all the exported
718 functions. This includes any functions you re-export from other
719 packages. However, if the consumer of your package also imports those
720 functions from the original package, they will I<not> be cleaned.
721
722 If you pass any parameters for L<Moose::Util::MetaRole>, this method will
723 generate an C<init_meta> for you as well (see below for details). This
724 C<init_meta> will call C<Moose::Util::MetaRole::apply_metaroles> and
725 C<Moose::Util::MetaRole::apply_base_class_roles> as needed.
726
727 Note that if any of these methods already exist, they will not be
728 overridden, you will have to use C<build_import_methods> to get the
729 coderef that would be installed.
730
731 This method accepts the following parameters:
732
733 =over 8
734
735 =item * with_meta => [ ... ]
736
737 This list of function I<names only> will be wrapped and then exported. The
738 wrapper will pass the metaclass object for the caller as its first argument.
739
740 Many sugar functions will need to use this metaclass object to do something to
741 the calling package.
742
743 =item * as_is => [ ... ]
744
745 This list of function names or sub references will be exported as-is. You can
746 identify a subroutine by reference, which is handy to re-export some other
747 module's functions directly by reference (C<\&Some::Package::function>).
748
749 If you do export some other package's function, this function will never be
750 removed by the C<unimport> method. The reason for this is we cannot know if
751 the caller I<also> explicitly imported the sub themselves, and therefore wants
752 to keep it.
753
754 =item * trait_aliases => [ ... ]
755
756 This is a list of package names which should have shortened aliases exported,
757 similar to the functionality of L<aliased>. Each element in the list can be
758 either a package name, in which case the export will be named as the last
759 namespace component of the package, or an arrayref, whose first element is the
760 package to alias to, and second element is the alias to export.
761
762 =item * also => $name or \@names
763
764 This is a list of modules which contain functions that the caller
765 wants to export. These modules must also use C<Moose::Exporter>. The
766 most common use case will be to export the functions from C<Moose.pm>.
767 Functions specified by C<with_meta> or C<as_is> take precedence over
768 functions exported by modules specified by C<also>, so that a module
769 can selectively override functions exported by another module.
770
771 C<Moose::Exporter> also makes sure all these functions get removed
772 when C<unimport> is called.
773
774 =back
775
776 You can also provide parameters for C<Moose::Util::MetaRole::apply_metaroles>
777 and C<Moose::Util::MetaRole::base_class_roles>. Specifically, valid parameters
778 are "class_metaroles", "role_metaroles", and "base_class_roles".
779
780 =item B<< Moose::Exporter->build_import_methods(...) >>
781
782 Returns two or three code refs, one for C<import>, one for
783 C<unimport>, and optionally one for C<init_meta>, if the appropriate
784 options are passed in.
785
786 Accepts the additional C<install> option, which accepts an arrayref of method
787 names to install into your exporting package. The valid options are C<import>,
788 C<unimport>, and C<init_meta>. Calling C<setup_import_methods> is equivalent
789 to calling C<build_import_methods> with C<< install => [qw(import unimport
790 init_meta)] >> except that it doesn't also return the methods.
791
792 Used by C<setup_import_methods>.
793
794 =back
795
796 =head1 IMPORTING AND init_meta
797
798 If you want to set an alternative base object class or metaclass class, see
799 above for details on how this module can call L<Moose::Util::MetaRole> for
800 you.
801
802 If you want to do something that is not supported by this module, simply
803 define an C<init_meta> method in your class. The C<import> method that
804 C<Moose::Exporter> generates for you will call this method (if it exists). It
805 will always pass the caller to this method via the C<for_class> parameter.
806
807 Most of the time, your C<init_meta> method will probably just call C<<
808 Moose->init_meta >> to do the real work:
809
810   sub init_meta {
811       shift; # our class name
812       return Moose->init_meta( @_, metaclass => 'My::Metaclass' );
813   }
814
815 Keep in mind that C<build_import_methods> will return an C<init_meta>
816 method for you, which you can also call from within your custom
817 C<init_meta>:
818
819   my ( $import, $unimport, $init_meta ) =
820       Moose::Exporter->build_import_methods( ... );
821
822   sub import {
823      my $class = shift;
824
825      ...
826
827      $class->$import(...);
828
829      ...
830   }
831
832   sub unimport { goto &$unimport }
833
834   sub init_meta {
835      my $class = shift;
836
837      ...
838
839      $class->$init_meta(...);
840
841      ...
842   }
843
844 =head1 METACLASS TRAITS
845
846 The C<import> method generated by C<Moose::Exporter> will allow the
847 user of your module to specify metaclass traits in a C<-traits>
848 parameter passed as part of the import:
849
850   use Moose -traits => 'My::Meta::Trait';
851
852   use Moose -traits => [ 'My::Meta::Trait', 'My::Other::Trait' ];
853
854 These traits will be applied to the caller's metaclass
855 instance. Providing traits for an exporting class that does not create
856 a metaclass for the caller is an error.
857
858 =head1 BUGS
859
860 See L<Moose/BUGS> for details on reporting bugs.
861
862 =cut