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