File Coverage

blib/lib/Path/Dispatcher/Rule/Eq.pm
Criterion Covered Total %
statement 23 31 74.1
branch 10 20 50.0
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 38 58 65.5


line stmt bran cond sub pod time code
1             package Path::Dispatcher::Rule::Eq;
2             # ABSTRACT: predicate is a string equality
3              
4             our $VERSION = '1.07';
5              
6 31     31   238 use Moo;
  31         76  
  31         186  
7 31     31   10061 use Types::Standard qw(Str Bool);
  31         68  
  31         385  
8              
9             extends 'Path::Dispatcher::Rule';
10              
11             has string => (
12             is => 'ro',
13             isa => Str,
14             required => 1,
15             );
16              
17             has case_sensitive => (
18             is => 'ro',
19             isa => Bool,
20             default => 1,
21             );
22              
23             sub _match {
24 118     118   193 my $self = shift;
25 118         171 my $path = shift;
26              
27 118 100       285 if ($self->case_sensitive) {
28 116 100       397 return unless $path->path eq $self->string;
29             }
30             else {
31 2 50       13 return unless lc($path->path) eq lc($self->string);
32             }
33              
34 88         210 return {};
35             }
36              
37             sub _prefix_match {
38 0     0   0 my $self = shift;
39 0         0 my $path = shift;
40              
41 0         0 my $truncated = substr($path->path, 0, length($self->string));
42              
43 0 0       0 if ($self->case_sensitive) {
44 0 0       0 return unless $truncated eq $self->string;
45             }
46             else {
47 0 0       0 return unless lc($truncated) eq lc($self->string);
48             }
49              
50             return {
51 0         0 leftover => substr($path->path, length($self->string)),
52             };
53             }
54              
55             sub complete {
56 30     30 0 605 my $self = shift;
57 30         60 my $path = shift->path;
58 30         57 my $completed = $self->string;
59              
60             # by convention, complete does include the path itself if it
61             # is a complete match
62 30 100       92 return if length($path) >= length($completed);
63              
64 24         49 my $partial = substr($completed, 0, length($path));
65 24 50       64 if ($self->case_sensitive) {
66 24 100       104 return unless $partial eq $path;
67             }
68             else {
69 0 0       0 return unless lc($partial) eq lc($path);
70             }
71              
72 16         50 return $completed;
73             }
74              
75             __PACKAGE__->meta->make_immutable;
76 31     31   30191 no Moo;
  31         78  
  31         152  
77              
78             1;
79              
80             __END__