Rssfilter/FromHash.pm

filter: Statementstmt 97.3% 72 / 74 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 95.7% 89 / 93 CC 5 SCAR 4.7
CC
5
Cov
95%
from_hash
3.0
split_for_ctor
2.0
_from_hash
2.0
CRAP 1.6
« Rssfilter/FromYaml.pm ↑ Summary Rssfilter/Match/Category.pm »
1 # ABSTRACT: a role for creating App::Rssfilter objects from a configuration hash
2  
3  
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 package App::Rssfilter::FromHash;
8 {
9 6 $App::Rssfilter::FromHash::VERSION = '0.07';
10 }
11  
12 6 ▶use Moo::Role; # test harness uses Test::Routine, which wants a Moose-y role, son no Role::Tiny
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use Method::Signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use Scalar::Util qw< blessed >;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 6 requires 'add_feed';
17 6 requires 'add_rule';
18 6 requires 'add_group';
19  
20  
21 6 ▶method from_hash( $config_ref, @config ) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine from_hash: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ > 0 0 2 2
22 2 ▶ if ( 'HASH' ne ref $config_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("HASH" ne ref $config_ref) 2 0 2
23 2 unshift @config, $config_ref;
24 2 $config_ref = {};
25 }
26 2 $self->_from_hash( %{ $config_ref }, @config );
27 }
28  
29 6 ▶method _from_hash( %config ) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _from_hash: called CC=2 SCAR=6.9
30 3 my $group = $self->new( name => $config{name} );
31  
32 3 map { $group->add_feed( @{ $_ } ) } $self->split_for_ctor( @{ $config{feeds} } );
33 3 map { $group->add_rule( @{ $_ } ) } $self->split_for_ctor( @{ $config{rules} } );
34  
35 3 for my $subgroup ( @{ $config{groups} } ) {
36 1 $group->add_group( $self->_from_hash( %{ $subgroup } ) );
37 }
38  
39 3 return $group;
40 }
41  
42  
43 6 ▶method split_for_ctor( @list ) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine split_for_ctor: called CC=2 SCAR=6.9
44 7 my @results;
45 7 ▶ while( @list ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@list) 7 7 14
46 6 ▶ use experimental 'smartmatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
47 6 ▶ use feature 'switch';
Subroutine BEGIN: called CC=1 SCAR=0.0
48 7 given( shift @list ) {
49 7 when( 'HASH' eq ref $_ ) { push @results, [ %{ $_ } ] }
50 0 when( 'ARRAY' eq ref $_ ) { push @results, [ @{ $_ } ] }
51 # squash 'Argument "foo" isn't numeric in smart match'
52 6 when( '' ne ref $_ ) { push @results, [ $_ ] }
53 1 default { push @results, [ $_ => shift @list ] };
54 };
55 }
56 7 return @results;
57 }
58  
59 6 1;
60  
61 __END__
« Rssfilter/FromYaml.pm ↑ Summary Rssfilter/Match/Category.pm »