| 1 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 2 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Get the latest or previous version of an RSS feed | ||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||
| 7 | package App::Rssfilter::Feed; | ||||||||||||||||||||||||||||||||||||||||||||
| 8 | 15 | $App::Rssfilter::Feed::VERSION = '0.08'; # TRIAL | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 15 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 10 | 15 | with 'App::Rssfilter::Logger'; | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 15 | ▶ | use Method::Signatures; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | 15 | has name => ( | |||||||||||||||||||||||||||||||||||||||||||
| 16 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||
| 17 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 15 | has url => ( | |||||||||||||||||||||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||
| 23 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | has rules => ( | ||||||||||||||||||||||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||
| 29 | 5 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 30 | 15 | ); | |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | has user_agent => ( | ||||||||||||||||||||||||||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||
| 35 | 15 | ▶ | default => sub { use Mojo::UserAgent; Mojo::UserAgent->new }, | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 15 | ); | |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | has storage => ( | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=10.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 15 | ▶ | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | default => method { | |||||||||||||||||||||||||||||||||||||||||||
| 42 | use App::Rssfilter::Feed::Storage; | ||||||||||||||||||||||||||||||||||||||||||||
| 43 | App::Rssfilter::Feed::Storage->new( | ||||||||||||||||||||||||||||||||||||||||||||
| 44 | name => $self->name, | ||||||||||||||||||||||||||||||||||||||||||||
| 45 | 15 | ); | |||||||||||||||||||||||||||||||||||||||||||
| 46 | }, | ||||||||||||||||||||||||||||||||||||||||||||
| 47 | 15 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BUILDARGS: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 14 | ▶ | |||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | method BUILDARGS( %options ) { | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 4 | if( 1 == keys %options ) { | |||||||||||||||||||||||||||||||||||||||||||
| 51 | @options{ 'name', 'url' } = each %options; | ||||||||||||||||||||||||||||||||||||||||||||
| 52 | 14 | delete $options{ $options{ name } }; | |||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 54 | return { %options }; | ||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 56 | 15 | ▶ | |||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
add_rule: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 15 | ▶ | |||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | ▶ | method add_rule( $rule, @rule_options ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($rule) and $rule->isa("App::Rssfilter::Rule")
MC/DC50%1/2
builtin::blessed($rule) and $rule->isa("App::Rssfilter::Rule")
builtin::blessed($rule)
$rule->isa("App::Rssfilter::Rule")
Truth table66%2/3
A and B
A= builtin::blessed($rule)B= $rule->isa("App::Rssfilter::Rule")
| |||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | use Scalar::Util qw< blessed >; | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 15 | ▶ | if ( ! blessed( $rule ) or ! $rule->isa( 'App::Rssfilter::Rule' ) ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | unshift @rule_options, $rule; # restore original @_ | |||||||||||||||||||||||||||||||||||||||||||
| 62 | use App::Rssfilter::Rule; | ||||||||||||||||||||||||||||||||||||||||||||
| 63 | $rule = App::Rssfilter::Rule->new( @rule_options ); | ||||||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | } | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | ||||||||||||||||||||||||||||||||||||||||||||
| 66 | push @{ $self->rules }, $rule; | ||||||||||||||||||||||||||||||||||||||||||||
| 67 | return $self; | ||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 69 | 15 | ▶ | |||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
update: called CC=13 SCAR=26.0
Branch: 5 branches
Condition33%1/3
$Method::Signatures::mutc{"cache"}{"ArrayRef"} ||= "Method::Signatures"->_make_constraint("ArrayRef")
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"ArrayRef"} ||= "Method::Signatures"->_make_constraint("ArrayRef")
$Method::Signatures::mutc{"cache"}{"ArrayRef"}
"Method::Signatures"->_make_constraint("ArrayRef")
Truth table33%1/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"ArrayRef"}B= "Method::Signatures"->_make_constraint("ArrayRef")
| |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 8 | ||||||||||||||||||||||||||||||||||||||||||||
| 71 | 8 | method update( ArrayRef :$rules = [], :$storage = $self->storage ) { | |||||||||||||||||||||||||||||||||||||||||||
| 72 | $storage = $storage->set_name( $self->name ); | ||||||||||||||||||||||||||||||||||||||||||||
| 73 | 8 | my $old = $storage->load_existing; | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 8 | ▶ | |||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 3 | my $headers = {}; | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 3 | if( defined( my $last_modified = $storage->last_modified ) ) { | |||||||||||||||||||||||||||||||||||||||||||
| 77 | $self->logger->debug( "last update was $last_modified" ); | ||||||||||||||||||||||||||||||||||||||||||||
| 78 | ${ $headers }{ 'If-Modified-Since' } = $last_modified; | ||||||||||||||||||||||||||||||||||||||||||||
| 79 | 8 | } | |||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | my $latest = $self->user_agent->get( | ||||||||||||||||||||||||||||||||||||||||||||
| 82 | $self->url, | ||||||||||||||||||||||||||||||||||||||||||||
| 83 | $headers | ||||||||||||||||||||||||||||||||||||||||||||
| 84 | 8 | ); | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 8 | ||||||||||||||||||||||||||||||||||||||||||||
| 86 | my @rules = @{ $rules }; | ||||||||||||||||||||||||||||||||||||||||||||
| 87 | 8 | ▶ | push @rules, @{ $self->rules }; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 5 | ||||||||||||||||||||||||||||||||||||||||||||
| 89 | 5 | if ( 200 == $latest->res->code ) { | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 5 | $self->logger->debug( 'found a newer feed!' ); | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 5 | $self->logger->debug( 'filtering '. $self->name ); | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 6 | ▶ | my $new = $latest->res->dom; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 6 | for my $rule ( @rules ) { | |||||||||||||||||||||||||||||||||||||||||||
| 94 | $self->logger->debugf( 'applying %s => %s to new feed', $rule->condition_name, $rule->action_name ) if $self->logger->is_debug; | ||||||||||||||||||||||||||||||||||||||||||||
| 95 | 5 | $rule->constrain( $new ); | |||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 97 | $storage->save_feed( $new ); | ||||||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 8 | ||||||||||||||||||||||||||||||||||||||||||||
| 100 | 8 | if ( defined $old ) { | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 8 | $self->logger->debug( 'collecting guids from old feed' ); | |||||||||||||||||||||||||||||||||||||||||||
| 102 | for my $rule ( @rules ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 103 | $rule->constrain( $old ); | ||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 106 | 15 | } | |||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1; | ||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||