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