File Coverage

blib/lib/Path/IsDev/Role/Matcher/FullPath/Is/Any.pm
Criterion Covered Total %
statement 39 47 82.9
branch 3 6 50.0
condition n/a
subroutine 8 8 100.0
pod 1 1 100.0
total 51 62 82.2


line stmt bran cond sub pod time code
1 14     14   66590 use 5.008; # utf8
  14         53  
  14         646  
2 14     14   81 use strict;
  14         25  
  14         439  
3 14     14   1203 use warnings;
  14         30  
  14         793  
4 14     14   1226 use utf8;
  14         37  
  14         80  
5              
6             package Path::IsDev::Role::Matcher::FullPath::Is::Any;
7              
8             our $VERSION = '1.001002';
9              
10             # ABSTRACT: Match if the current directory is the same directory from a list of absolute paths.
11              
12             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
13              
14             sub _path {
15 64     64   401 require Path::Tiny;
16 64         844 Path::Tiny->VERSION('0.004');
17 64         398 goto &Path::Tiny::path;
18             }
19              
20 14     14   2756 use Role::Tiny;
  14         3916  
  14         92  
21              
22              
23              
24              
25              
26              
27              
28              
29              
30              
31              
32              
33              
34              
35              
36              
37              
38              
39              
40              
41              
42              
43             sub _fullpath_is {
44 64     64   140 my ( $self, $result_object, $this, $comparator ) = @_;
45              
46 64         110 my $context = {};
47              
48 64         174 $context->{tests} = [];
49              
50 64         168 $context->{test_path} = "$comparator";
51              
52 64         157 my $path = _path($comparator);
53              
54 64 50       1678 if ( not $path->exists ) {
55 0         0 push @{ $context->{tests} }, { 'test_path_exists?' => 0 };
  0         0  
56 0         0 $result_object->add_reason( $self, 0, "comparative path $comparator does not exist", $context );
57 0         0 return;
58             }
59              
60 64         13524 push @{ $context->{tests} }, { 'test_path_exists?' => 1 };
  64         265  
61              
62 64         259 my $realpath = $path->realpath;
63              
64 64         8496 $context->{source_realpath} = "$this";
65 64         431 $context->{test_realpath} = "$realpath";
66              
67 64 50       470 if ( not $realpath eq $this ) {
68 64         415 push @{ $context->{tests} }, { 'test_realpath_eq_source_realpath?' => 0 };
  64         313  
69 64         342 $result_object->add_reason( $self, 0, "$this ne $realpath", $context );
70 64         469 return;
71             }
72 0         0 push @{ $context->{tests} }, { 'test_realpath_eq_source_realpath?' => 1 };
  0         0  
73 0         0 $result_object->add_reason( $self, 1, "$this eq $realpath", $context );
74 0         0 return 1;
75             }
76              
77              
78              
79              
80              
81              
82              
83              
84              
85              
86              
87              
88              
89             sub fullpath_is_any {
90 32     32 1 102 my ( $self, $result_object, @dirnames ) = @_;
91 32         1012 my $current = $result_object->path->realpath;
92 32         4516 for my $dirname (@dirnames) {
93 64 50       221 return 1 if $self->_fullpath_is( $result_object, $current, $dirname );
94             }
95 32         287 return;
96             }
97              
98             1;
99              
100             __END__
101              
102             =pod
103              
104             =encoding UTF-8
105              
106             =head1 NAME
107              
108             Path::IsDev::Role::Matcher::FullPath::Is::Any - Match if the current directory is the same directory from a list of absolute paths.
109              
110             =head1 VERSION
111              
112             version 1.001002
113              
114             =head1 METHODS
115              
116             =head2 C<fullpath_is_any>
117              
118             Note, this is usually invoked on directories anyway.
119              
120             if ( $self->fullpath_is_any( $result_object, '/usr/', '/usr/bin/foo' )) {
121              
122             }
123              
124             Matches if any of the provided paths C<realpath>'s correspond to C<< $result_object->path->realpath >>
125              
126             =head1 PRIVATE METHODS
127              
128             =head2 C<_fullpath_is>
129              
130             $class->_fullpath_is( $result_object, $source_path, $comparison_path );
131              
132             Does not match if C<$comparison_path> does not exist.
133              
134             Otherwise, compare C<$source_path> vs C<< $comparison_path->realpath >>, and return if they match.
135              
136             =begin MetaPOD::JSON v1.1.0
137              
138             {
139             "namespace":"Path::IsDev::Role::Matcher::FullPath::Is::Any",
140             "interface":"role"
141             }
142              
143              
144             =end MetaPOD::JSON
145              
146             =head1 AUTHOR
147              
148             Kent Fredric <kentfredric@gmail.com>
149              
150             =head1 COPYRIGHT AND LICENSE
151              
152             This software is copyright (c) 2014 by Kent Fredric <kentfredric@gmail.com>.
153              
154             This is free software; you can redistribute it and/or modify it under
155             the same terms as the Perl 5 programming language system itself.
156              
157             =cut