File Coverage

blib/lib/Path/Dispatcher/Rule/Metadata.pm
Criterion Covered Total %
statement 18 18 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 25 25 100.0


line stmt bran cond sub pod time code
1             package Path::Dispatcher::Rule::Metadata;
2             # ABSTRACT: match path's metadata
3              
4             our $VERSION = '1.07';
5              
6 31     31   226 use Moo;
  31         71  
  31         182  
7 31     31   10079 use Type::Utils qw(class_type);
  31         104  
  31         324  
8 31     31   18178 use Types::Standard qw(Str);
  31         73  
  31         184  
9             extends 'Path::Dispatcher::Rule';
10              
11             has field => (
12             is => 'ro',
13             isa => Str,
14             required => 1,
15             );
16              
17             has matcher => (
18             is => 'ro',
19             isa => class_type("Path::Dispatcher::Rule"),
20             required => 1,
21             );
22              
23             sub _match {
24 3     3   7 my $self = shift;
25 3         7 my $path = shift;
26 3         15 my $got = $path->get_metadata($self->field);
27              
28             # wow, offensive.. but powerful
29 3         12 my $metadata_path = $path->clone_path($got);
30 3 100       226 return unless $self->matcher->match($metadata_path);
31              
32             return {
33 2         29 leftover => $path->path,
34             };
35             }
36              
37             __PACKAGE__->meta->make_immutable;
38 31     31   18782 no Moo;
  31         75  
  31         137  
39              
40             1;
41              
42             __END__