File Coverage

blib/lib/Path/IsDev/Role/HeuristicSet.pm
Criterion Covered Total %
statement 38 40 95.0
branch 5 6 83.3
condition n/a
subroutine 12 12 100.0
pod 1 1 100.0
total 56 59 94.9


line stmt bran cond sub pod time code
1 14     14   783959 use 5.008; # utf8;
  14         55  
  14         938  
2 14     14   79 use strict;
  14         29  
  14         466  
3 14     14   89 use warnings;
  14         43  
  14         669  
4 14     14   3467 use utf8;
  14         41  
  14         93  
5              
6             package Path::IsDev::Role::HeuristicSet;
7              
8             our $VERSION = '1.001002';
9              
10             # ABSTRACT: Role for sets of Heuristics.
11              
12             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
13              
14              
15              
16              
17              
18              
19              
20              
21              
22              
23              
24              
25 127     127   630 sub _use_module { require Module::Runtime; goto &Module::Runtime::use_module }
  127         558  
26 208     208   905 sub _com_mn { require Module::Runtime; goto &Module::Runtime::compose_module_name; }
  208         989  
27             ## no critic (Subroutines::ProhibitCallsToUnexportedSubs)
28 13     13   187 sub _debug { require Path::IsDev; goto &Path::IsDev::debug }
  13         48  
29              
30 14     14   4166 use Role::Tiny qw( requires );
  14         21197  
  14         108  
31              
32              
33              
34              
35              
36              
37              
38             requires 'modules';
39              
40             sub _expand_heuristic {
41 160     160   270 my ( undef, $hn ) = @_;
42 160         349 return _com_mn( 'Path::IsDev::Heuristic', $hn );
43             }
44              
45             sub _expand_negative_heuristic {
46 48     48   90 my ( undef, $hn ) = @_;
47 48         121 return _com_mn( 'Path::IsDev::NegativeHeuristic', $hn );
48             }
49              
50             sub _load_module {
51 127     127   374 my ( undef, $module ) = @_;
52 127         415 return _use_module($module);
53             }
54              
55              
56              
57              
58              
59              
60              
61              
62              
63              
64              
65             sub matches {
66 16     16 1 591 my ( $self, $result_object ) = @_;
67 16         88 TESTS: for my $module ( $self->modules ) {
68 127         813 $self->_load_module($module);
69 127 100       3411 if ( $module->can('excludes') ) {
70 48 50       220 if ( $module->excludes($result_object) ) {
71 0         0 _debug( $module->name . q[ excludes path ] . $result_object->path );
72 0         0 return;
73             }
74 48         165 next TESTS;
75             }
76 79 100       357 next unless $module->matches($result_object);
77 13         74 my $name = $module->name;
78 13         337 _debug( $name . q[ matched path ] . $result_object->path );
79 13         133 return 1;
80             }
81 3         42 return;
82             }
83              
84             1;
85              
86             __END__
87              
88             =pod
89              
90             =encoding UTF-8
91              
92             =head1 NAME
93              
94             Path::IsDev::Role::HeuristicSet - Role for sets of Heuristics.
95              
96             =head1 VERSION
97              
98             version 1.001002
99              
100             =head1 ROLE REQUIRES
101              
102             =head2 C<modules>
103              
104             Please provide a method that returns a list of modules that comprise heuristics.
105              
106             =head1 METHODS
107              
108             =head2 C<matches>
109              
110             Determine if the C<HeuristicSet> contains a match.
111              
112             if( $hs->matches( $result_object ) ) {
113             # one of hs->modules() matched $result_object->path
114             }
115              
116             =begin MetaPOD::JSON v1.1.0
117              
118             {
119             "namespace":"Path::IsDev::Role::HeuristicSet",
120             "interface":"role"
121             }
122              
123              
124             =end MetaPOD::JSON
125              
126             =head1 AUTHOR
127              
128             Kent Fredric <kentfredric@gmail.com>
129              
130             =head1 COPYRIGHT AND LICENSE
131              
132             This software is copyright (c) 2014 by Kent Fredric <kentfredric@gmail.com>.
133              
134             This is free software; you can redistribute it and/or modify it under
135             the same terms as the Perl 5 programming language system itself.
136              
137             =cut