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.08'; |
5
|
|
|
|
|
|
|
|
6
|
31
|
|
|
31
|
|
237
|
use Moo; |
|
31
|
|
|
|
|
65
|
|
|
31
|
|
|
|
|
210
|
|
7
|
31
|
|
|
31
|
|
11155
|
use MooX::TypeTiny; |
|
31
|
|
|
|
|
69
|
|
|
31
|
|
|
|
|
169
|
|
8
|
31
|
|
|
31
|
|
22481
|
use Types::Standard qw(Str Bool); |
|
31
|
|
|
|
|
72
|
|
|
31
|
|
|
|
|
202
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
extends 'Path::Dispatcher::Rule'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has string => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
isa => Str, |
15
|
|
|
|
|
|
|
required => 1, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has case_sensitive => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
isa => Bool, |
21
|
|
|
|
|
|
|
default => 1, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _match { |
25
|
118
|
|
|
118
|
|
179
|
my $self = shift; |
26
|
118
|
|
|
|
|
159
|
my $path = shift; |
27
|
|
|
|
|
|
|
|
28
|
118
|
100
|
|
|
|
285
|
if ($self->case_sensitive) { |
29
|
116
|
100
|
|
|
|
374
|
return unless $path->path eq $self->string; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else { |
32
|
2
|
50
|
|
|
|
13
|
return unless lc($path->path) eq lc($self->string); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
88
|
|
|
|
|
208
|
return {}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _prefix_match { |
39
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
40
|
0
|
|
|
|
|
0
|
my $path = shift; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
my $truncated = substr($path->path, 0, length($self->string)); |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
0
|
if ($self->case_sensitive) { |
45
|
0
|
0
|
|
|
|
0
|
return unless $truncated eq $self->string; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else { |
48
|
0
|
0
|
|
|
|
0
|
return unless lc($truncated) eq lc($self->string); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return { |
52
|
0
|
|
|
|
|
0
|
leftover => substr($path->path, length($self->string)), |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub complete { |
57
|
30
|
|
|
30
|
0
|
477
|
my $self = shift; |
58
|
30
|
|
|
|
|
73
|
my $path = shift->path; |
59
|
30
|
|
|
|
|
74
|
my $completed = $self->string; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# by convention, complete does include the path itself if it |
62
|
|
|
|
|
|
|
# is a complete match |
63
|
30
|
100
|
|
|
|
94
|
return if length($path) >= length($completed); |
64
|
|
|
|
|
|
|
|
65
|
24
|
|
|
|
|
53
|
my $partial = substr($completed, 0, length($path)); |
66
|
24
|
50
|
|
|
|
60
|
if ($self->case_sensitive) { |
67
|
24
|
100
|
|
|
|
80
|
return unless $partial eq $path; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else { |
70
|
0
|
0
|
|
|
|
0
|
return unless lc($partial) eq lc($path); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
16
|
|
|
|
|
49
|
return $completed; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
77
|
31
|
|
|
31
|
|
31115
|
no Moo; |
|
31
|
|
|
|
|
82
|
|
|
31
|
|
|
|
|
204
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=pod |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=encoding UTF-8 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 NAME |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Path::Dispatcher::Rule::Eq - predicate is a string equality |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 VERSION |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
version 1.08 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 SYNOPSIS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $rule = Path::Dispatcher::Rule::Eq->new( |
98
|
|
|
|
|
|
|
string => 'comment', |
99
|
|
|
|
|
|
|
block => sub { display_comment(shift->pos(1)) }, |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 DESCRIPTION |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Rules of this class simply check whether the string is equal to the path. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 string |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 SUPPORT |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Path-Dispatcher> |
113
|
|
|
|
|
|
|
(or L<bug-Path-Dispatcher@rt.cpan.org|mailto:bug-Path-Dispatcher@rt.cpan.org>). |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 AUTHOR |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Shawn M Moore, C<< <sartak at bestpractical.com> >> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This software is copyright (c) 2020 by Shawn M Moore. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
124
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |