| 1 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: load and save RSS feeds as files | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | package App::Rssfilter::Feed::Storage; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 17 | $App::Rssfilter::Feed::Storage::VERSION = '0.07'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 17 | ▶ | use Method::Signatures; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 17 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 17 | with 'App::Rssfilter::Logger'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 17 | ▶ | use Mojo::DOM; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 17 | ▶ | use Path::Class::File 0.26; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 17 | ▶ | use Path::Class::Dir; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 17 | ▶ | use HTTP::Date; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | has path => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 8 | ▶ | default => sub { Path::Class::Dir->new() }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 13 | ▶ | coerce => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 13 | ▶ | return $_[0] if 'Path::Class::Dir' eq ref $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | if ( 1 == @_ && 'Array' eq ref $_[0] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
1 == @_ and "Array" eq ref $_[0]
MC/DC0%0/2
1 == @_ and "Array" eq ref $_[0]
1 == @_
"Array" eq ref $_[0]
Truth table33%1/3
A and B
A= 1 == @_B= "Array" eq ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | @_ = @{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | Path::Class::Dir->new( @_ ) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 17 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 17 | ▶ | method path_push( @paths ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
path_push: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | return App::Rssfilter::Feed::Storage->new( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | path => $self->path->subdir( @paths ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | name => $self->name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 17 | has name => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 17 | ▶ | method set_name( $new_name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
set_name: called CC=7 SCAR=19.9
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | ▶ | return $self if defined($self->name) && defined($new_name) ? $self->name eq $new_name : ! defined($self->name) && ! defined($new_name); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%4/6
defined $self->name and defined $new_name
defined $self->name || defined $new_name
MC/DC50%1/2
defined $self->name and defined $new_name
defined $self->name
defined $new_name
MC/DC50%1/2
defined $self->name || defined $new_name
defined $self->name
defined $new_name
Truth table66%2/3
A and B
A= defined $self->nameB= defined $new_name
Truth table66%2/3
A || B
A= defined $self->nameB= defined $new_name
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | return App::Rssfilter::Feed::Storage->new( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | name => $new_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | path => $self->path, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 17 | has _file_path => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 17 | ▶ | method _build__file_path { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
_build__file_path: called CC=4 SCAR=14.3
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | die "no name" if not defined $self->name; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | die "no path" if not defined $self->path; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | $self->path->file( $self->name .'.rss' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 17 | has last_modified => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | clearer => '_clear_last_modified', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 17 | ▶ | method _build_last_modified { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
_build_last_modified: called CC=3 SCAR=11.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | if ( my $stat = $self->_file_path->stat ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | return time2str $stat->mtime; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | return time2str 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 17 | ▶ | method load_existing { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
load_existing: called CC=3 SCAR=11.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | $self->logger->debugf( 'loading '. $self->_file_path ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | my $stat = $self->_file_path->stat; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | ▶ | return Mojo::DOM->new if not defined $stat; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | $self->_clear_last_modified; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | return Mojo::DOM->new( scalar $self->_file_path->slurp ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 17 | ▶ | method save_feed( $feed ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
save_feed: called CC=4 SCAR=14.0
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | $self->logger->debugf( 'writing out new filtered feed to '. $self->_file_path ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | my $target_dir = $self->_file_path->dir; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | ▶ | if( not defined $target_dir->stat ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | $self->logger->debug( "no $target_dir directory! making one" ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | $target_dir->mkpath; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | $self->_file_path->spew( $feed->to_xml ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $self->_clear_last_modified; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||