File Coverage

blib/lib/Path/Dispatcher/Rule/Eq.pm
Criterion Covered Total %
statement 20 28 71.4
branch 10 20 50.0
condition n/a
subroutine 4 5 80.0
pod 0 1 0.0
total 34 54 62.9


line stmt bran cond sub pod time code
1             package Path::Dispatcher::Rule::Eq;
2 32     32   137 use Any::Moose;
  32         35  
  32         136  
3             extends 'Path::Dispatcher::Rule';
4              
5             has string => (
6             is => 'ro',
7             isa => 'Str',
8             required => 1,
9             );
10              
11             has case_sensitive => (
12             is => 'ro',
13             isa => 'Bool',
14             default => 1,
15             );
16              
17             sub _match {
18 118     118   101 my $self = shift;
19 118         114 my $path = shift;
20              
21 118 100       218 if ($self->case_sensitive) {
22 116 100       372 return unless $path->path eq $self->string;
23             }
24             else {
25 2 50       10 return unless lc($path->path) eq lc($self->string);
26             }
27              
28 88         155 return {};
29             }
30              
31             sub _prefix_match {
32 0     0   0 my $self = shift;
33 0         0 my $path = shift;
34              
35 0         0 my $truncated = substr($path->path, 0, length($self->string));
36              
37 0 0       0 if ($self->case_sensitive) {
38 0 0       0 return unless $truncated eq $self->string;
39             }
40             else {
41 0 0       0 return unless lc($truncated) eq lc($self->string);
42             }
43              
44             return {
45 0         0 leftover => substr($path->path, length($self->string)),
46             };
47             }
48              
49             sub complete {
50 30     30 0 117 my $self = shift;
51 30         42 my $path = shift->path;
52 30         39 my $completed = $self->string;
53              
54             # by convention, complete does include the path itself if it
55             # is a complete match
56 30 100       74 return if length($path) >= length($completed);
57              
58 24         31 my $partial = substr($completed, 0, length($path));
59 24 50       41 if ($self->case_sensitive) {
60 24 100       68 return unless $partial eq $path;
61             }
62             else {
63 0 0       0 return unless lc($partial) eq lc($path);
64             }
65              
66 16         37 return $completed;
67             }
68              
69             __PACKAGE__->meta->make_immutable;
70 32     32   20444 no Any::Moose;
  32         49  
  32         127  
71              
72             1;
73              
74             __END__