File Coverage

blib/lib/Path/Dispatcher/Match.pm
Criterion Covered Total %
statement 20 23 86.9
branch 4 4 100.0
condition n/a
subroutine 6 7 85.7
pod 2 3 66.6
total 32 37 86.4


line stmt bran cond sub pod time code
1             package Path::Dispatcher::Match;
2 32     32   127 use Any::Moose;
  32         52  
  32         162  
3              
4 32     32   22144 use Path::Dispatcher::Path;
  32         52  
  32         874  
5 32     32   167 use Path::Dispatcher::Rule;
  32         37  
  32         7033  
6              
7             has path => (
8             is => 'ro',
9             isa => 'Path::Dispatcher::Path',
10             required => 1,
11             );
12              
13             has leftover => (
14             is => 'ro',
15             isa => 'Str',
16             );
17              
18             has rule => (
19             is => 'ro',
20             isa => 'Path::Dispatcher::Rule',
21             required => 1,
22             handles => ['payload'],
23             );
24              
25             has positional_captures => (
26             is => 'ro',
27             isa => 'ArrayRef[Str|Undef]',
28             default => sub { [] },
29             );
30              
31             has named_captures => (
32             is => 'ro',
33             isa => 'HashRef[Str|Undef]',
34             default => sub { {} },
35             );
36              
37             has parent => (
38             is => 'ro',
39             isa => 'Path::Dispatcher::Match',
40             predicate => 'has_parent',
41             );
42              
43             sub run {
44 69     69 1 1330 my $self = shift;
45              
46 69         181 local $_ = $self->path;
47 69         352 return scalar $self->rule->run($self, @_);
48             }
49              
50             sub pos {
51 9     9 1 1438 my $self = shift;
52 9         10 my $index = shift;
53              
54 9 100       22 return undef if $index == 0;
55              
56 8 100       17 $index-- if $index > 0;
57              
58 8         37 return $self->positional_captures->[$index];
59             }
60              
61             sub named {
62 0     0 0   my $self = shift;
63 0           my $key = shift;
64 0           return $self->named_captures->{$key};
65             }
66              
67             __PACKAGE__->meta->make_immutable;
68 32     32   150 no Any::Moose;
  32         51  
  32         116  
69              
70             1;
71              
72             __END__