| 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
| |||||||||||
| 22 | 2 | ▶ | if ( 'HASH' ne ref $config_ref ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||