line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Path::Dispatcher::Declarative; |
2
|
18
|
|
|
18
|
|
883693
|
use strict; |
|
18
|
|
|
|
|
48
|
|
|
18
|
|
|
|
|
1597
|
|
3
|
18
|
|
|
18
|
|
110
|
use warnings; |
|
18
|
|
|
|
|
32
|
|
|
18
|
|
|
|
|
626
|
|
4
|
18
|
|
|
18
|
|
517
|
use 5.008001; |
|
18
|
|
|
|
|
73
|
|
|
18
|
|
|
|
|
1208
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
7
|
|
|
|
|
|
|
|
8
|
18
|
|
|
18
|
|
19492
|
use Path::Dispatcher; |
|
18
|
|
|
|
|
2680983
|
|
|
18
|
|
|
|
|
934
|
|
9
|
18
|
|
|
18
|
|
14361
|
use Path::Dispatcher::Declarative::Builder; |
|
18
|
|
|
|
|
61
|
|
|
18
|
|
|
|
|
2280
|
|
10
|
18
|
|
|
18
|
|
39995
|
use Sub::Exporter; |
|
18
|
|
|
|
|
389523
|
|
|
18
|
|
|
|
|
142
|
|
11
|
|
|
|
|
|
|
|
12
|
18
|
|
|
18
|
|
4084
|
use constant dispatcher_class => 'Path::Dispatcher'; |
|
18
|
|
|
|
|
39
|
|
|
18
|
|
|
|
|
2096
|
|
13
|
18
|
|
|
18
|
|
159
|
use constant builder_class => 'Path::Dispatcher::Declarative::Builder'; |
|
18
|
|
|
|
|
35
|
|
|
18
|
|
|
|
|
2922
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $CALLER; # Sub::Exporter doesn't make this available |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $exporter = Sub::Exporter::build_exporter({ |
18
|
|
|
|
|
|
|
into_level => 1, |
19
|
|
|
|
|
|
|
groups => { |
20
|
|
|
|
|
|
|
default => \&build_sugar, |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
}); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub import { |
25
|
22
|
|
|
22
|
|
5242
|
my $self = shift; |
26
|
22
|
|
|
|
|
66
|
my $pkg = caller; |
27
|
|
|
|
|
|
|
|
28
|
22
|
|
|
|
|
52
|
my @args = grep { !/^-base$/i } @_; |
|
28
|
|
|
|
|
152
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# just loading the class.. |
31
|
22
|
50
|
|
|
|
127
|
return if @args == @_; |
32
|
|
|
|
|
|
|
|
33
|
22
|
|
|
|
|
46
|
do { |
34
|
18
|
|
|
18
|
|
126
|
no strict 'refs'; |
|
18
|
|
|
|
|
33
|
|
|
18
|
|
|
|
|
12047
|
|
35
|
22
|
|
|
|
|
44
|
push @{ $pkg . '::ISA' }, $self; |
|
22
|
|
|
|
|
473
|
|
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
22
|
|
|
|
|
53
|
local $CALLER = $pkg; |
39
|
|
|
|
|
|
|
|
40
|
22
|
|
|
|
|
121
|
$exporter->($self, @args); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub build_sugar { |
44
|
22
|
|
|
22
|
0
|
2353
|
my ($class, $group, $arg) = @_; |
45
|
|
|
|
|
|
|
|
46
|
22
|
|
|
|
|
38
|
my $into = $CALLER; |
47
|
|
|
|
|
|
|
|
48
|
22
|
|
|
|
|
91
|
$class->populate_defaults($arg); |
49
|
|
|
|
|
|
|
|
50
|
22
|
|
|
|
|
586
|
my $dispatcher = $class->dispatcher_class->new(name => $into); |
51
|
|
|
|
|
|
|
|
52
|
22
|
|
|
|
|
1949
|
my $builder = $class->builder_class->new( |
53
|
|
|
|
|
|
|
dispatcher => $dispatcher, |
54
|
|
|
|
|
|
|
%$arg, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
return { |
58
|
8
|
|
|
8
|
|
150
|
dispatcher => sub { $builder->dispatcher }, |
59
|
4
|
|
|
4
|
|
91
|
rewrite => sub { $builder->rewrite(@_) }, |
60
|
58
|
|
|
58
|
|
7467
|
on => sub { $builder->on(@_) }, |
61
|
17
|
|
|
17
|
|
27423
|
under => sub { $builder->under(@_) }, |
62
|
3
|
|
|
3
|
|
59
|
redispatch_to => sub { $builder->redispatch_to(@_) }, |
63
|
1
|
|
|
1
|
|
11
|
enum => sub { $builder->enum(@_) }, |
64
|
9
|
|
|
9
|
|
164
|
next_rule => sub { $builder->next_rule(@_) }, |
65
|
0
|
|
|
0
|
|
0
|
last_rule => sub { $builder->last_rule(@_) }, |
66
|
0
|
|
|
0
|
|
0
|
complete => sub { $builder->complete(@_) }, |
|
|
|
|
0
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
5
|
|
|
5
|
|
72
|
then => sub (&) { $builder->then(@_) }, |
69
|
6
|
|
|
6
|
|
70
|
chain => sub (&) { $builder->chain(@_) }, |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# NOTE on shift if $into: if caller is $into, then this function is |
72
|
|
|
|
|
|
|
# being used as sugar otherwise, it's probably a method call, so |
73
|
|
|
|
|
|
|
# discard the invocant |
74
|
0
|
0
|
|
0
|
|
0
|
dispatch => sub { shift if caller ne $into; $builder->dispatch(@_) }, |
|
0
|
|
|
|
|
0
|
|
75
|
46
|
50
|
|
46
|
|
48195
|
run => sub { shift if caller ne $into; $builder->run(@_) }, |
|
46
|
|
|
|
|
245
|
|
76
|
22
|
|
|
|
|
2306
|
}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub populate_defaults { |
80
|
22
|
|
|
22
|
0
|
44
|
my $class = shift; |
81
|
22
|
|
|
|
|
39
|
my $arg = shift; |
82
|
|
|
|
|
|
|
|
83
|
22
|
|
|
|
|
47
|
for my $option ('token_delimiter', 'case_sensitive_tokens') { |
84
|
44
|
100
|
|
|
|
144
|
next if exists $arg->{$option}; |
85
|
40
|
100
|
|
|
|
520
|
next unless $class->can($option); |
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
6
|
my $default = $class->$option; |
88
|
1
|
50
|
|
|
|
13
|
next unless defined $default; # use the builder's default |
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
6
|
$arg->{$option} = $class->$option; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |