line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Namespace::Dispatch; |
2
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
682
|
use 5.010; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
65
|
|
5
|
2
|
|
|
2
|
|
5120
|
use UNIVERSAL::filename; |
|
2
|
|
|
|
|
12105
|
|
|
2
|
|
|
|
|
23
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub import { |
8
|
7
|
|
|
7
|
|
3141
|
my $pkg = shift; |
9
|
7
|
|
|
|
|
15
|
my $caller = caller; |
10
|
7
|
50
|
|
|
|
104
|
my $meta = ref($caller->meta) if $caller->can("meta"); |
11
|
|
|
|
|
|
|
|
12
|
7
|
50
|
33
|
|
|
27
|
if ( $meta && $meta =~ m/(Class$|Role$)/ ) { |
13
|
0
|
|
|
|
|
0
|
eval qq{ use Moose::Role }; |
14
|
0
|
|
|
|
|
0
|
Moose::Util::apply_all_roles($caller, $pkg, {-excludes => "import"}); |
15
|
|
|
|
|
|
|
} else { |
16
|
7
|
|
|
|
|
15
|
for (qw(has_leaf dispatch leaves)) { |
17
|
21
|
|
|
|
|
21
|
*{$caller . "::" . $_} = *{$_}; |
|
21
|
|
|
|
|
364
|
|
|
21
|
|
|
|
|
36
|
|
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub has_leaf { |
24
|
18
|
100
|
|
18
|
0
|
52
|
my $class = ref($_[0]) ? ref(shift) : shift; |
25
|
18
|
|
|
|
|
19
|
my $name = shift; |
26
|
18
|
50
|
|
|
|
89
|
my @leaves = @{$class->leaves} if $class->can("leaves"); |
|
18
|
|
|
|
|
36
|
|
27
|
18
|
100
|
|
|
|
78
|
if ( $name ~~ @leaves ) { |
28
|
12
|
|
|
|
|
56
|
return $class . "::" . ucfirst($name); |
29
|
|
|
|
|
|
|
} else { |
30
|
6
|
|
|
|
|
16
|
return 0; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub dispatch { |
35
|
15
|
100
|
|
15
|
0
|
54
|
my $class = ref($_[0]) ? ref(shift) : shift; |
36
|
15
|
|
|
|
|
20
|
my $next = shift; |
37
|
15
|
|
|
|
|
33
|
my $handler = $class->has_leaf($next); |
38
|
|
|
|
|
|
|
|
39
|
15
|
100
|
|
|
|
35
|
if ($handler) { |
40
|
|
|
|
|
|
|
|
41
|
10
|
|
|
1
|
|
658
|
eval qq{ use $handler }; |
|
1
|
|
|
1
|
|
411
|
|
|
1
|
|
|
1
|
|
36
|
|
|
1
|
|
|
1
|
|
8
|
|
|
1
|
|
|
1
|
|
6
|
|
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
1
|
|
4
|
|
|
1
|
|
|
1
|
|
416
|
|
|
1
|
|
|
1
|
|
38
|
|
|
1
|
|
|
1
|
|
8
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
419
|
|
|
1
|
|
|
|
|
38
|
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
379
|
|
|
1
|
|
|
|
|
35
|
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
98
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
382
|
|
|
1
|
|
|
|
|
35
|
|
|
1
|
|
|
|
|
11
|
|
42
|
10
|
100
|
|
|
|
123
|
die $@ if $@; |
43
|
|
|
|
|
|
|
|
44
|
9
|
100
|
|
|
|
58
|
if ($handler->can("dispatch")) { |
45
|
8
|
|
|
|
|
26
|
return $handler->dispatch(@_); |
46
|
|
|
|
|
|
|
} else { |
47
|
1
|
|
|
|
|
12
|
die "$handler is not set up yet (forgot to use Namespace::Dispatch?)"; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
} else { |
51
|
5
|
|
|
|
|
68
|
return $class; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub leaves { |
57
|
23
|
100
|
|
23
|
0
|
73
|
my $class = ref($_[0]) ? ref(shift) : shift; |
58
|
23
|
|
|
|
|
89
|
my $file = $class->filename; |
59
|
23
|
|
|
|
|
235
|
$file =~ s{.pm$}{}g; |
60
|
2
|
|
|
2
|
|
1511
|
use File::Basename; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
546
|
|
61
|
23
|
|
|
|
|
2071
|
my @submodules = map { $_ = lc basename($_) } glob "$file/*.pm"; |
|
72
|
|
|
|
|
1882
|
|
62
|
23
|
|
|
|
|
48
|
map { $_ =~ s{\.pm$}{}; } @submodules; |
|
72
|
|
|
|
|
220
|
|
63
|
23
|
|
|
|
|
130
|
[@submodules]; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
__END__ |