File Coverage

blib/lib/Path/Dispatcher/Path.pm
Criterion Covered Total %
statement 22 22 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 0 2 0.0
total 30 32 93.7


line stmt bran cond sub pod time code
1             package Path::Dispatcher::Path;
2             # ABSTRACT: path and some optional metadata
3              
4             our $VERSION = '1.08';
5              
6 32     32   239 use Moo;
  32         80  
  32         207  
7 32     32   11323 use MooX::TypeTiny;
  32         88  
  32         208  
8 32     32   19422 use Types::Standard qw(Str HashRef);
  32         78  
  32         189  
9 32     32   20313 use overload q{""} => sub { shift->path };
  32     5   77  
  32         309  
  5         956  
10              
11             has path => (
12             is => 'ro',
13             isa => Str,
14             predicate => 'has_path',
15             );
16              
17             has metadata => (
18             is => 'ro',
19             isa => HashRef,
20             predicate => 'has_metadata',
21             );
22              
23             # allow Path::Dispatcher::Path->new($path)
24             around BUILDARGS => sub {
25             my $orig = shift;
26             my $self = shift;
27              
28             if (@_ == 1 && !ref($_[0])) {
29             unshift @_, 'path';
30             }
31              
32             $self->$orig(@_);
33             };
34              
35             sub clone_path {
36 201     201 0 304 my $self = shift;
37 201         302 my $path = shift;
38              
39 201         4102 return $self->new({ %$self, path => $path, @_ });
40             }
41              
42             sub get_metadata {
43 3     3 0 93 my $self = shift;
44 3         9 my $name = shift;
45              
46 3         15 return $self->metadata->{$name};
47             }
48              
49             __PACKAGE__->meta->make_immutable;
50 32     32   7332 no Moo;
  32         93  
  32         175  
51              
52             1;
53              
54             __END__
55              
56             =pod
57              
58             =encoding UTF-8
59              
60             =head1 NAME
61              
62             Path::Dispatcher::Path - path and some optional metadata
63              
64             =head1 VERSION
65              
66             version 1.08
67              
68             =head1 SYNOPSIS
69              
70             my $path = Path::Dispatcher::Path->new(
71             path => "/REST/Ticket/1",
72             metadata => {
73             http_method => "DELETE",
74             },
75             );
76              
77             $path->path; # /REST/Ticket/1
78             $path->get_metadata("http_method"); # DELETE
79              
80             =head1 ATTRIBUTES
81              
82             =head2 path
83              
84             A string representing the path. C<Path::Dispatcher::Path> is basically a boxed
85             string. :)
86              
87             =head2 metadata
88              
89             A hash representing arbitrary metadata. The L<Path::Dispatcher::Rule::Metadata>
90             rule is designed to match against members of this hash.
91              
92             =head1 SUPPORT
93              
94             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Path-Dispatcher>
95             (or L<bug-Path-Dispatcher@rt.cpan.org|mailto:bug-Path-Dispatcher@rt.cpan.org>).
96              
97             =head1 AUTHOR
98              
99             Shawn M Moore, C<< <sartak at bestpractical.com> >>
100              
101             =head1 COPYRIGHT AND LICENSE
102              
103             This software is copyright (c) 2020 by Shawn M Moore.
104              
105             This is free software; you can redistribute it and/or modify it under
106             the same terms as the Perl 5 programming language system itself.
107              
108             =cut