File Coverage

blib/lib/Exporter/Declare/Magic/Sub.pm
Criterion Covered Total %
statement 20 22 90.9
branch 2 4 50.0
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 29 33 87.8


line stmt bran cond sub pod time code
1             package Exporter::Declare::Magic::Sub;
2 1     1   701 use strict;
  1         2  
  1         31  
3 1     1   5 use warnings;
  1         2  
  1         27  
4              
5 1     1   4 use base 'Exporter::Declare::Export::Sub';
  1         2  
  1         1238  
6              
7             sub inject {
8 14     14 1 7042 my $self = shift;
9 14         30 my ($class, $name) = @_;
10              
11 14         48 $self->SUPER::inject( $class, $name );
12              
13 14 50       155 return unless $self->parser;
14              
15 14         126 my $parser_sub = $self->exported_by->export_meta->parsers_get( $self->parser );
16              
17 14 50       398 if ( $parser_sub ) {
18 0         0 require Devel::Declare;
19 0         0 Devel::Declare->setup_for(
20             $class,
21             { $name => { const => $parser_sub } }
22             );
23             }
24             else {
25 14         216 require Devel::Declare::Interface;
26 14         734 require Exporter::Declare::Magic::Parser;
27 14         32 Devel::Declare::Interface::enhance(
28             $class,
29             $name,
30             $self->parser,
31             );
32             }
33             }
34              
35             sub parser {
36 42     42 1 188 my $self = shift;
37 42         90 return $self->_data->{parser};
38             }
39              
40             1;
41              
42             =head1 NAME
43              
44             Exporter::Declare::Magic::Sub - Export class for subs which are exported.
45              
46             =head1 DESCRIPTION
47              
48             Export class for subs which are exported. Overrides inject() in order to hook
49             into L on parsed exports.
50              
51             =head1 OVERRIDEN METHODS
52              
53             =over 4
54              
55             =item $export->inject( $class, $name );
56              
57             Inject the sub, and apply the L magic.
58              
59             =back
60              
61             =head1 NEW METHODS
62              
63             =over 4
64              
65             =item $parser_name = export->parser()
66              
67             Get the name of the parse this sub should use with L empty when
68             no parse should be used.
69              
70             =back
71              
72             =head1 AUTHORS
73              
74             Chad Granum L
75              
76             =head1 COPYRIGHT
77              
78             Copyright (C) 2010 Chad Granum
79              
80             Exporter-Declare is free software; Standard perl licence.
81              
82             Exporter-Declare is distributed in the hope that it will be useful, but
83             WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
84             FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.