Declare.pm

filter: Statementstmt 91.3% 116 / 127 Branchbran 75.0% 27 / 36 Conditioncond 57.8% 11 / 19 MC/DCmcdc 25.0% 3 / 12 Subroutinesub 96.7% 30 / 31 Podpod 91.6% 11 / 12 totaltotal 83.5% 198 / 237 CC 30 SCAR 13.6
CC
30
Cov
85%
after_import
14.4
_parse_export_params
6.0
_add_export
5.2
CRAP 3.9
« Declare/Specs.pm ↑ Summary Declare/Meta.pm »
1 package Exporter::Declare;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Scalar::Util qw/reftype/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use aliased 'Exporter::Declare::Meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use aliased 'Exporter::Declare::Specs';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use aliased 'Exporter::Declare::Export::Sub';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use aliased 'Exporter::Declare::Export::Variable';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use aliased 'Exporter::Declare::Export::Generator';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 ▶BEGIN { Meta->new(__PACKAGE__) }
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 our $VERSION = '0.114';
16 4 our @CARP_NOT = qw/
17 Exporter::Declare
18 Exporter::Declare::Specs
19 Exporter::Declare::Meta
20 Exporter::Declare::Magic
21 /;
22  
23 4 default_exports(
24 qw/
25 import
26 exports
27 default_exports
28 import_options
29 import_arguments
30 export_tag
31 export
32 gen_export
33 default_export
34 gen_default_export
35 /
36 );
37  
38 4 exports(
39 qw/
40 reexport
41 export_to
42 /
43 );
44  
45 4 export_tag(
46 magic => qw/
47 !export
48 !gen_export
49 !default_export
50 !gen_default_export
51 /
52 );
53  
54 13 ▶sub import {
Subroutine import: called CC=4 SCAR=13.9
55 13 my $class = shift;
56 13 my $caller = caller;
57  
58 13 ▶ $class->alter_import_args( $caller, \@_ )
Branch: 1 branch
BranchTrueFalseTotal
if $class->can("alter_import_args") 0 13 13
59 if $class->can('alter_import_args');
60  
61 13 my $specs = _parse_specs( $class, @_ );
62  
63 13 ▶ $class->before_import( $caller, $specs )
Branch: 1 branch
BranchTrueFalseTotal
if $class->can("before_import") 2 11 13
64 if $class->can('before_import');
65  
66 13 $specs->export($caller);
67  
68 13 ▶ $class->after_import( $caller, $specs )
Branch: 1 branch
BranchTrueFalseTotal
if $class->can("after_import") 6 7 13
69 if $class->can('after_import');
70 }
71  
72 6 ▶sub after_import {
Subroutine after_import: called CC=5 SCAR=26.7
Pod undocumented
73 6 my $class = shift;
74 6 my ( $caller, $specs ) = @_;
75 6 Meta->new($caller);
76  
77 6 ▶ return unless my $args = $specs->config->{'magic'};
Branch: 1 branch
BranchTrueFalseTotal
unless my $args = $specs->config->{"magic"} 6 0 6
78 0 ▶ $args = ['-default'] unless ref $args && ref $args eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args and ref $args eq "ARRAY" 0 0 0
Condition0%0/3
ref $args and ref $args eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $args and ref $args eq "ARRAY"
ref $args ref $args eq "ARRAY"
Truth table0%0/3
A and B
A= ref $argsB= ref $args eq "ARRAY"
ABresult
0X0
100
111
79  
80 croak "Exporter::Declare::Magic must be installed seperately for -magic to work"
81 0 ▶ unless eval { require Exporter::Declare::Magic };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { require Exporter::Declare::Magic } } 0 0 0
82  
83 0 warn "Exporter::Declare -magic is deprecated. Please use Exporter::Declare::Magic directly";
84  
85 0 export_to( 'Exporter::Declare::Magic', $caller, @$args );
86 }
87  
88 13 ▶sub _parse_specs {
Subroutine _parse_specs: called CC=3 SCAR=11.2
89 13 my $class = _find_export_class( \@_ );
90 13 my (@args) = @_;
91  
92 # XXX This is ugly!
93 unshift @args => '-default'
94 if $class eq __PACKAGE__
95 13 ▶ && grep { $_ eq '-magic' } @args;
Branch: 1 branch
BranchTrueFalseTotal
if $class eq __PACKAGE__ and grep {$_ eq "-magic";} @args 0 13 13
Condition66%2/3
$class eq __PACKAGE__ and grep {$_ eq "-magic";} @args
!ll&&!rl&&r
760
MC/DC0%0/2
$class eq __PACKAGE__ and grep {$_ eq "-magic";} @args
$class eq __PACKAGE__ grep {$_ eq "-magic";} @args
Truth table66%2/3
A and B
A= $class eq __PACKAGE__B= grep {$_ eq "-magic";} @args
ABresult
0X0
100
111
96  
97 13 return Specs->new( $class, @args );
98 }
99  
100 0 ▶sub export_to {
Subroutine export_to: not called CC=1 SCAR=6.9
Pod documented
101 0 my $class = _find_export_class( \@_ );
102 0 my ( $dest, @args ) = @_;
103 0 my $specs = _parse_specs( $class, @args );
104 0 $specs->export($dest);
105 0 return $specs;
106 }
107  
108 6 ▶sub export_tag {
Subroutine export_tag: called CC=1 SCAR=0.0
Pod documented
109 6 my $class = _find_export_class( \@_ );
110 6 my ( $tag, @list ) = @_;
111 6 $class->export_meta->export_tags_push( $tag, @list );
112 }
113  
114 7 ▶sub exports {
Subroutine exports: called CC=2 SCAR=6.9
Pod documented
115 7 my $class = _find_export_class( \@_ );
116 7 my $meta = $class->export_meta;
117 7 _export( $class, undef, $_ ) for @_;
118 7 $meta->export_tags_get('all');
119 }
120  
121 7 ▶sub default_exports {
Subroutine default_exports: called CC=2 SCAR=6.9
Pod documented
122 7 my $class = _find_export_class( \@_ );
123 7 my $meta = $class->export_meta;
124 7 $meta->export_tags_push( 'default', _export( $class, undef, $_ ) ) for @_;
125 7 $meta->export_tags_get('default');
126 }
127  
128 4 ▶sub export {
Subroutine export: called CC=1 SCAR=0.0
Pod documented
129 4 my $class = _find_export_class( \@_ );
130 4 _export( $class, undef, @_ );
131 }
132  
133 1 ▶sub gen_export {
Subroutine gen_export: called CC=1 SCAR=0.0
Pod documented
134 1 my $class = _find_export_class( \@_ );
135 1 _export( $class, Generator(), @_ );
136 }
137  
138 4 ▶sub default_export {
Subroutine default_export: called CC=1 SCAR=0.0
Pod documented
139 4 my $class = _find_export_class( \@_ );
140 4 my $meta = $class->export_meta;
141 4 $meta->export_tags_push( 'default', _export( $class, undef, @_ ) );
142 }
143  
144 1 ▶sub gen_default_export {
Subroutine gen_default_export: called CC=1 SCAR=0.0
Pod documented
145 1 my $class = _find_export_class( \@_ );
146 1 my $meta = $class->export_meta;
147 1 $meta->export_tags_push( 'default', _export( $class, Generator(), @_ ) );
148 }
149  
150 1 ▶sub import_options {
Subroutine import_options: called CC=2 SCAR=6.9
Pod documented
151 1 my $class = _find_export_class( \@_ );
152 1 my $meta = $class->export_meta;
153 1 $meta->options_add($_) for @_;
154 }
155  
156 1 ▶sub import_arguments {
Subroutine import_arguments: called CC=2 SCAR=6.9
Pod documented
157 1 my $class = _find_export_class( \@_ );
158 1 my $meta = $class->export_meta;
159 1 $meta->arguments_add($_) for @_;
160 }
161  
162 66 ▶sub _parse_export_params {
Subroutine _parse_export_params: called CC=6 SCAR=17.9
163 66 my ( $class, $expclass, $name, @param ) = @_;
164 66 ▶ my $ref = ref( $param[-1] ) ? pop(@param) : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $param[-1] ? : 6 60 66
165 66 my $meta = $class->export_meta;
166  
167 66 ▶ ( $ref, $name ) = $meta->get_ref_from_package($name)
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 60 6 66
168 unless $ref;
169  
170 66 ( my $type, $name ) = ( $name =~ m/^([\$\@\&\%]?)(.*)$/ );
171 66 ▶ $type = "" if $type eq '&';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "&" 56 10 66
172  
173 66 my $fullname = "$type$name";
174  
175 return (
176 66 ▶ class => $class,
Condition100%4/4
$expclass || undef
l!l
264
$type || ''
l!l
561
MC/DC100%1/1
$expclass || undef
$expclass
MC/DC100%1/1
$type || ''
$type
Truth table100%2/2
A
A= $expclass
Aresult
11
00
Truth table100%2/2
A
A= $type
Aresult
11
00
177 export_class => $expclass || undef,
178 name => $name,
179 ref => $ref,
180 type => $type || "",
181 fullname => $fullname,
182 args => \@param,
183 );
184 }
185  
186 66 ▶sub _export {
Subroutine _export: called CC=1 SCAR=0.0
187 66 _add_export( _parse_export_params(@_) );
188 }
189  
190 66 ▶sub _add_export {
Subroutine _add_export: called CC=5 SCAR=16.4
191 66 my %params = @_;
192 66 my $meta = $params{class}->export_meta;
193 $params{export_class} ||=
194 66 ▶ reftype( $params{ref} ) eq 'CODE'
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($params{'ref'}) eq 'CODE' ? : 59 5 64
Condition66%2/3
$params{"export_class"} ||= builtin::reftype($params{"ref"}) eq "CODE" ? "Exporter::Declare::Export::Sub" : "Exporter::Declare::Export::Variable"
l!l&&r!l&&!r
2640
MC/DC0%0/2
$params{"export_class"} ||= builtin::reftype($params{"ref"}) eq "CODE" ? "Exporter::Declare::Export::Sub" : "Exporter::Declare::Export::Variable"
$params{"export_class"} builtin::reftype($params{"ref"}) eq "CODE" ? "Exporter::Declare::Export::Sub" : "Exporter::Declare::Export::Variable"
Truth table66%2/3
A ||= B
A= $params{"export_class"}B= builtin::reftype($params{"ref"}) eq "CODE" ? "Exporter::Declare::Export::Sub" : "Exporter::Declare::Export::Variable"
ABresult
1X1
011
000
195 ? Sub()
196 : Variable();
197  
198 $params{export_class}->new(
199 $params{ref},
200 exported_by => $params{class},
201 (
202 $params{type} ? ( type => 'variable' )
203 : ( type => 'sub' )
204 ),
205 (
206 0 ▶ $params{extra_exporter_props} ? %{$params{extra_exporter_props}}
Branch: 2 branches
BranchTrueFalseTotal
$params{'type'} ? : 5 61 66
$params{'extra_exporter_props'} ? : 0 66 66
207 : ()
208 ),
209 );
210  
211 66 $meta->exports_add( $params{fullname}, $params{ref} );
212  
213 66 return $params{fullname};
214 }
215  
216 45 ▶sub _is_exporter_class {
Subroutine _is_exporter_class: called CC=5 SCAR=16.1
217 45 my ($name) = @_;
218  
219 45 ▶ return 0 unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 45 45
220  
221 # This is to work around a bug in older versions of UNIVERSAL::can which
222 # would issue a warning about $name->can() when $name was not a valid
223 # package.
224 # This will first verify that $name is a namespace, if not it will return false.
225 # If the namespace defines 'export_meta' we know it is an exporter.
226 # If there is no @ISA array in the namespace we simply return false,
227 # otherwise we fall back to $name->can().
228 {
229 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
230 4 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
231 45 ▶ return 0 unless keys %{"$name\::"};
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{"${name}::";} 29 16 45
232 16 ▶ return 1 if defined *{"$name\::export_meta"}{CODE};
Branch: 1 branch
BranchTrueFalseTotal
if defined *{"${name}::export_meta";}{"CODE"} 14 2 16
233 2 ▶ return 0 unless @{"$name\::ISA"};
Branch: 1 branch
BranchTrueFalseTotal
unless @{"${name}::ISA";} 1 1 2
234 }
235  
236 1 return eval { $name->can('export_meta'); 1 };
237 }
238  
239 45 ▶sub _find_export_class {
Subroutine _find_export_class: called CC=3 SCAR=11.0
240 45 my $args = shift;
241  
242 45 ▶ return shift(@$args)
Branch: 1 branch
BranchTrueFalseTotal
if @$args and _is_exporter_class(@$args) 15 30 45
Condition66%2/3
@$args and _is_exporter_class(@$args)
!ll&&!rl&&r
03015
MC/DC50%1/2
@$args and _is_exporter_class(@$args)
@$args _is_exporter_class(@$args)
Truth table66%2/3
A and B
A= @$argsB= _is_exporter_class(@$args)
ABresult
0X0
100
111
243 if @$args && _is_exporter_class(@$args);
244  
245 30 return caller(1);
246 }
247  
248 2 ▶sub reexport {
Subroutine reexport: called CC=2 SCAR=7.6
Pod documented
249 2 my $from = pop;
250 2 ▶ my $class = shift || caller;
Condition33%1/3
shift() || &CORE::GLOBAL::caller()
l!l&&r!l&&!r
020
MC/DC0%0/2
shift() || &CORE::GLOBAL::caller()
shift() &CORE::GLOBAL::caller()
Truth table33%1/3
A || B
A= shift()B= &CORE::GLOBAL::caller()
ABresult
1X1
011
000
251 2 $class->export_meta->reexport($from);
252 }
253  
254 4 1;
255  
256 =head1 NAME
257  
258 Exporter::Declare - Exporting done right
259  
260 =head1 DESCRIPTION
261  
262 Exporter::Declare is a meta-driven exporting tool. Exporter::Declare tries to
263 adopt all the good features of other exporting tools, while throwing away
264 horrible interfaces. Exporter::Declare also provides hooks that allow you to add
265 options and arguments for import. Finally, Exporter::Declare's meta-driven
266 system allows for top-notch introspection.
267  
268 =head1 FEATURES
269  
270 =over 4
271  
272 =item Declarative exporting (like L<Moose> for exporting)
273  
274 =item Meta-driven for introspection
275  
276 =item Customizable import() method
277  
278 =item Export groups (tags)
279  
280 =item Export generators for subs and variables
281  
282 =item Clear and concise OO API
283  
284 =item Exports are blessed, allowing for more introspection
285  
286 =item Import syntax based off of L<Sub::Exporter>
287  
288 =item Packages export aliases
289  
290 =back
291  
292 =head1 SYNOPSIS
293  
294 =head2 EXPORTER
295  
296 package Some::Exporter;
297 use Exporter::Declare;
298  
299 default_exports qw/ do_the_thing /;
300 exports qw/ subA subB $SCALAR @ARRAY %HASH /;
301  
302 # Create a couple tags (import lists)
303 export_tag subs => qw/ subA subB do_the_thing /;
304 export_tag vars => qw/ $SCALAR @ARRAY %HASH /;
305  
306 # These are simple boolean options, pass '-optionA' to enable it.
307 import_options qw/ optionA optionB /;
308  
309 # These are options which slurp in the next argument as their value, pass
310 # '-optionC' => 'foo' to give it a value.
311 import_arguments qw/ optionC optionD /;
312  
313 export anon_export => sub { ... };
314 export '@anon_var' => [...];
315  
316 default_export a_default => sub { 'default!' }
317  
318 our $X = "x";
319 default_export '$X';
320  
321 my $iterator = 'a';
322 gen_export unique_class_id => sub {
323 my $current = $iterator++;
324 return sub { $current };
325 };
326  
327 gen_default_export '$my_letter' => sub {
328 my $letter = $iterator++;
329 return \$letter;
330 };
331  
332 # You can create a function to mangle the arguments before they are
333 # parsed into a Exporter::Declare::Spec object.
334 sub alter_import_args {
335 my ($class, $importer, $args) = @_;
336  
337 # fiddle with args before importing routines are called
338 @$args = grep { !/^skip_/ } @$args
339 }
340  
341 # There is no need to fiddle with import() or do any wrapping.
342 # the $specs data structure means you generally do not need to parse
343 # arguments yourself (but you can if you want using alter_import_args())
344  
345 # Change the spec object before export occurs
346 sub before_import {
347 my $class = shift;
348 my ( $importer, $specs ) = @_;
349  
350 if ($specs->config->{optionA}) {
351 # Modify $spec attributes accordingly
352 }
353 }
354  
355 # Use spec object after export occurs
356 sub after_import {
357 my $class = shift;
358 my ( $importer, $specs ) = @_;
359  
360 do_option_a() if $specs->config->{optionA};
361  
362 do_option_c( $specs->config->{optionC} )
363 if $specs->config->{optionC};
364  
365 print "-subs tag was used\n"
366 if $specs->config->{subs};
367  
368 print "exported 'subA'\n"
369 if $specs->exports->{subA};
370 }
371  
372 ...
373  
374 =head2 IMPORTER
375  
376 package Some::Importer;
377 use Some::Exporter qw/ subA $SCALAR !%HASH /,
378 -default => { -prefix => 'my_' },
379 qw/ -optionA !-optionB /,
380 subB => { -as => 'sub_b' };
381  
382 subA();
383 print $SCALAR;
384 sub_b();
385 my_do_the_thing();
386  
387 ...
388  
389 =head1 IMPORT INTERFACE
390  
391 Importing from a package that uses Exporter::Declare will be familiar to anyone
392 who has imported from modules before. Arguments are all assumed to be export
393 names, unless prefixed with C<-> or C<:> In which case they may be a tag or an
394 option. Exports without a sigil are assumed to be code exports, variable
395 exports must be listed with their sigil.
396  
397 Items prefixed with the C<!> symbol are forcefully excluded, regardless of any
398 listed item that may normally include them. Tags can also be excluded, this
399 will effectively exclude everything in the tag.
400  
401 Tags are simply lists of exports, the exporting class may define any number of
402 tags. Exporter::Declare also has the concept of options, they have the same
403 syntax as tags. Options may be boolean or argument based. Boolean options are
404 actually 3 value, undef, false C<!>, or true. Argument based options will grab
405 the next value in the arguments list as their own, regardless of what type of
406 value it is.
407  
408 When you use the module, or call import(), all the arguments are transformed
409 into an L<Exporter::Declare::Specs> object. Arguments are parsed for you into a
410 list of imports, and a configuration hash in which tags/options are keys. Tags
411 are listed in the config hash as true, false, or undef depending on if they
412 were included, negated, or unlisted. Boolean options will be treated in the
413 same way as tags. Options that take arguments will have the argument as their
414 value.
415  
416 =head2 SELECTING ITEMS TO IMPORT
417  
418 Exports can be subs, or package variables (scalar, hash, array). For subs
419 simply ask for the sub by name, you may optionally prefix the subs name with
420 the sub sigil C<&>. For variables list the variable name along with its sigil
421 C<$, %, or @>.
422  
423 use Some::Exporter qw/ somesub $somescalar %somehash @somearray /;
424  
425 =head2 TAGS
426  
427 Every exporter automatically has the following 3 tags, in addition they may
428 define any number of custom tags. Tags can be specified by their name prefixed
429 by either C<-> or C<:>.
430  
431 =over 4
432  
433 =item -all
434  
435 This tag may be used to import everything the exporter provides.
436  
437 =item -default
438  
439 This tag is used to import the default items exported. This will be used when
440 no argument is provided to import.
441  
442 =item -alias
443  
444 Every package has an alias that it can export. This is the last segment of the
445 packages namespace. IE C<My::Long::Package::Name::Foo> could export the C<Foo()>
446 function. These alias functions simply return the full package name as a
447 string, in this case C<'My::Long::Package::Name::Foo'>. This is similar to
448 L<aliased>.
449  
450 The -alias tag is a shortcut so that you do not need to think about what the
451 alias name would be when adding it to the import arguments.
452  
453 use My::Long::Package::Name::Foo -alias;
454  
455 my $foo = Foo()->new(...);
456  
457 =back
458  
459 =head2 RENAMING IMPORTED ITEMS
460  
461 You can prefix, suffix, or completely rename the items you import. Whenever an
462 item is followed by a hash in the import list, that hash will be used for
463 configuration. Configuration items always start with a dash C<->.
464  
465 The 3 available configuration options that effect import names are C<-prefix>,
466 C<-suffix>, and C<-as>. If C<-as> is seen it will be used as is. If prefix or
467 suffix are seen they will be attached to the original name (unless -as is
468 present in which case they are ignored).
469  
470 use Some::Exporter subA => { -as => 'DoThing' },
471 subB => { -prefix => 'my_', -suffix => '_ok' };
472  
473 The example above will import C<subA()> under the name C<DoThing()>. It will
474 also import C<subB()> under the name C<my_subB_ok()>.
475  
476 You may als specify a prefix and/or suffix for tags. The following example will
477 import all the default exports with 'my_' prefixed to each name.
478  
479 use Some::Exporter -default => { -prefix => 'my_' };
480  
481 =head2 OPTIONS
482  
483 Some exporters will recognise options. Options look just like tags, and are
484 specified the same way. What options do, and how they effect things is
485 exporter-dependant.
486  
487 use Some::Exporter qw/ -optionA -optionB /;
488  
489 =head2 ARGUMENTS
490  
491 Some options require an argument. These options are just like other
492 tags/options except that the next item in the argument list is slurped in as
493 the option value.
494  
495 use Some::Exporter -ArgOption => 'Value, not an export',
496 -ArgTakesHash => { ... };
497  
498 Once again available options are exporter specific.
499  
500 =head2 PROVIDING ARGUMENTS FOR GENERATED ITEMS
501  
502 Some items are generated at import time. These items may accept arguments.
503 There are 3 ways to provide arguments, and they may all be mixed (though that
504 is not recommended).
505  
506 As a hash
507  
508 use Some::Exporter generated => { key => 'val', ... };
509  
510 As an array
511  
512 use Some::Exporter generated => [ 'Arg1', 'Arg2', ... ];
513  
514 As an array in a config hash
515  
516 use Some::Exporter generated => { -as => 'my_gen', -args => [ 'arg1', ... ]};
517  
518 You can use all three at once, but this is really a bad idea, documented for completeness:
519  
520 use Some::Exporter generated => { -as => 'my_gen, key => 'value', -args => [ 'arg1', 'arg2' ]}
521 generated => [ 'arg3', 'arg4' ];
522  
523 The example above will work fine, all the arguments will make it into the
524 generator. The only valid reason for this to work is that you may provide
525 arguments such as C<-prefix> to a tag that brings in generator(), while also
526 desiring to give arguments to generator() independently.
527  
528 =head1 PRIMARY EXPORT API
529  
530 With the exception of import(), all the following work equally well as
531 functions or class methods.
532  
533 =over 4
534  
535 =item import( @args )
536  
537 The import() class method. This turns the @args list into an
538 L<Exporter::Declare::Specs> object.
539  
540 =item exports( @add_items )
541  
542 Add items to be exported.
543  
544 =item @list = exports()
545  
546 Retrieve list of exports.
547  
548 =item default_exports( @add_items )
549  
550 Add items to be exported, and add them to the -default tag.
551  
552 =item @list = default_exports()
553  
554 List of exports in the -default tag
555  
556 =item import_options(@add_items)
557  
558 Specify boolean options that should be accepted at import time.
559  
560 =item import_arguments(@add_items)
561  
562 Specify options that should be accepted at import that take arguments.
563  
564 =item export_tag( $name, @add_items );
565  
566 Define an export tag, or add items to an existing tag.
567  
568 =back
569  
570 =head1 EXTENDED EXPORT API
571  
572 These all work fine in function or method form, however the syntax sugar will
573 only work in function form.
574  
575 =over 4
576  
577 =item reexport( $package )
578  
579 Make this exporter inherit all the exports and tags of $package. Works for
580 Exporter::Declare or Exporter.pm based exporters. Re-Exporting of
581 L<Sub::Exporter> based classes is not currently supported.
582  
583 =item export_to( $package, @args )
584  
585 Export to the specified class.
586  
587 =item export( $name )
588  
589 =item export( $name, $ref )
590  
591 export is a keyword that lets you export any 1 item at a time. The item can be
592 exported by name, or name + ref. When a ref is provided, the export is created,
593 but there is no corresponding variable/sub in the packages namespace.
594  
595 =item default_export( $name )
596  
597 =item default_export( $name, $ref )
598  
599 =item gen_export( $name )
600  
601 =item gen_export( $name, $ref )
602  
603 =item gen_default_export( $name )
604  
605 =item gen_default_export( $name, $ref )
606  
607 These all act just like export(), except that they add subrefs as generators,
608 and/or add exports to the -default tag.
609  
610 =back
611  
612 =head1 MAGIC
613  
614 Please use L<Exporter::Declare::Magic> directly from now on.
615  
616 =head2 DEPRECATED USAGE OF MAGIC
617  
618 use Exporter::Declare '-magic';
619  
620 This adds L<Devel::Declare> magic to several functions. It also allows you to
621 easily create or use parsers on your own exports. See
622 L<Exporter::Declare::Magic> for more details.
623  
624 You can also provide import arguments to L<Devel::Declare::Magic>
625  
626 # Arguments to -magic must be in an arrayref, not a hashref.
627 use Exporter::Declare -magic => [ '-default', '!export', -prefix => 'magic_' ];
628  
629 =head1 INTERNAL API
630  
631 Exporter/Declare.pm does not have much logic to speak of. Rather
632 Exporter::Declare is sugar on top of class meta data stored in
633 L<Exporter::Declare::Meta> objects. Arguments are parsed via
634 L<Exporter::Declare::Specs>, and also turned into objects. Even exports are
635 blessed references to the exported item itself, and handle the injection on
636 their own (See L<Exporter::Declare::Export>).
637  
638 =head1 META CLASS
639  
640 All exporters have a meta class, the only way to get the meta object is to call
641 the export_meta() method on the class/object that is an exporter. Any class
642 that uses Exporter::Declare gets this method, and a meta-object.
643  
644 =head1 AUTHORS
645  
646 Chad Granum L<exodist7@gmail.com>
647  
648 =head1 COPYRIGHT
649  
650 Copyright (C) 2010 Chad Granum
651  
652 Exporter-Declare is free software; Standard perl licence.
653  
654 Exporter-Declare is distributed in the hope that it will be useful, but
655 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
656 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
« Declare/Specs.pm ↑ Summary Declare/Meta.pm »