line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Devel::Declare::Interface; |
2
|
5
|
|
|
5
|
|
24
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
194
|
|
3
|
5
|
|
|
5
|
|
24
|
use warnings; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
162
|
|
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
25
|
use base 'Exporter'; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
465
|
|
6
|
5
|
|
|
5
|
|
27
|
use Carp; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
2930
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @EXPORT = qw/register_parser get_parser enhance/; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our %REGISTER = ( |
11
|
|
|
|
|
|
|
codeblock => [ 'Devel::Declare::Parser::Codeblock', 0 ], |
12
|
|
|
|
|
|
|
method => [ 'Devel::Declare::Parser::Method', 0 ], |
13
|
|
|
|
|
|
|
sublike => [ 'Devel::Declare::Parser::Sublike', 0 ], |
14
|
|
|
|
|
|
|
codelast => [ 'Devel::Declare::Parser', 0 ], |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub register_parser { |
18
|
8
|
|
|
8
|
1
|
25
|
my ( $name, $rclass ) = @_; |
19
|
8
|
50
|
|
|
|
31
|
croak( "No name for registration" ) unless $name; |
20
|
8
|
|
33
|
|
|
50
|
$rclass ||= caller; |
21
|
8
|
50
|
66
|
|
|
54
|
croak( "Parser $name already registered" ) |
22
|
|
|
|
|
|
|
if $REGISTER{ $name } && $REGISTER{ $name }->[0] ne $rclass; |
23
|
8
|
|
|
|
|
34
|
$REGISTER{ $name } = [ $rclass, 0 ]; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub get_parser { |
27
|
32
|
|
|
32
|
1
|
62
|
my ( $name ) = @_; |
28
|
32
|
50
|
|
|
|
74
|
croak( "No name for parser" ) unless $name; |
29
|
32
|
50
|
|
|
|
87
|
unless ( $REGISTER{$name} ) { |
30
|
0
|
0
|
|
|
|
0
|
if ( $name =~ m/::/g ) { |
31
|
0
|
0
|
|
|
|
0
|
return $name if eval "require $name; 1"; |
32
|
0
|
|
|
|
|
0
|
warn @_; |
33
|
|
|
|
|
|
|
} |
34
|
0
|
|
|
|
|
0
|
croak( "No parser found for $name" ); |
35
|
|
|
|
|
|
|
} |
36
|
32
|
100
|
|
|
|
91
|
unless( $REGISTER{$name}->[1] ) { |
37
|
6
|
50
|
|
|
|
425
|
eval "require " . $REGISTER{$name}->[0] . "; 1" || die($@); |
38
|
6
|
|
|
|
|
39
|
$REGISTER{$name}->[1]++; |
39
|
|
|
|
|
|
|
} |
40
|
32
|
|
|
|
|
76
|
return $REGISTER{ $name }->[0]; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub enhance { |
44
|
6
|
|
|
6
|
1
|
1746
|
my ( $for, $name, $parser, $type ) = @_; |
45
|
6
|
50
|
33
|
|
|
51
|
croak "You must specify a class, a function name, and a parser" |
|
|
|
33
|
|
|
|
|
46
|
|
|
|
|
|
|
unless $for && $name && $parser; |
47
|
6
|
|
50
|
|
|
30
|
$type ||= 'const'; |
48
|
|
|
|
|
|
|
|
49
|
6
|
|
|
|
|
27
|
require Devel::Declare; |
50
|
|
|
|
|
|
|
Devel::Declare->setup_for( |
51
|
|
|
|
|
|
|
$for, |
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
$name => { |
54
|
|
|
|
|
|
|
$type => sub { |
55
|
32
|
|
|
32
|
|
18001
|
my $pclass = get_parser( $parser ); |
56
|
32
|
|
|
|
|
255
|
my $parser = $pclass->new( $name, @_ ); |
57
|
32
|
|
|
|
|
110
|
$parser->process(); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
6
|
|
|
|
|
71
|
); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__ |