| 1 | package Bootylicious::FileIteratorLoader; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use base 'Mojo::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 11 | __PACKAGE__->attr('element_class'); | |||||||||||||||||||||||||||
| 9 | 11 | __PACKAGE__->attr('filter'); | |||||||||||||||||||||||||||
| 10 | 11 | __PACKAGE__->attr('root'); | |||||||||||||||||||||||||||
| 11 | 11 | __PACKAGE__->attr('path'); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use Mojo::ByteStream; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 11 | ▶ | use Mojo::Loader qw(load_class); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 11 | ▶ | use Bootylicious::Iterator; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | sub files { | ||||||||||||||||||||||||||||
| 18 | 31 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
files: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 31 | my $root = $self->root; | |||||||||||||||||||||||||||
| 21 | 31 | my $path = $self->path; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 31 | ▶ | return glob $root ? "$root/*" : "$path*"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub create_element { | ||||||||||||||||||||||||||||
| 27 | 74 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
create_element: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 74 | load_class($self->element_class); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 74 | return $self->element_class->new; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub load { | ||||||||||||||||||||||||||||
| 35 | 31 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
load: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 31 | my $iterator = shift; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 31 | ▶ | $iterator ||= Bootylicious::Iterator->new; | ||||||||||||||||||||||||||
|
Condition66%2/3
$iterator ||= "Bootylicious::Iterator"->new
MC/DC0%0/2
$iterator ||= "Bootylicious::Iterator"->new
$iterator
"Bootylicious::Iterator"->new
Truth table66%2/3
A ||= B
A= $iteratorB= "Bootylicious::Iterator"->new
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 31 | my $filter = $self->filter; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 31 | my @elements = (); | |||||||||||||||||||||||||||
| 43 | 31 | foreach my $file ($self->files) { | |||||||||||||||||||||||||||
| 44 | 89 | $file = Mojo::ByteStream->new($file)->decode('UTF-8')->to_string; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 89 | my $basename = File::Basename::basename($file); | |||||||||||||||||||||||||||
| 47 | 89 | ▶ | next if $filter && $basename !~ m/$filter/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$filter and not $basename =~ /$filter/
MC/DC50%1/2
$filter and not $basename =~ /$filter/
$filter
not $basename =~ /$filter/
Truth table66%2/3
A and not(B)
A= $filterB= not $basename =~ /$filter/
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 74 | my $element = $self->create_element; | |||||||||||||||||||||||||||
| 50 | 74 | $element->load($file); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 74 | push @elements, $element; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | $iterator->elements( | ||||||||||||||||||||||||||||
| 56 | 31 | [sort { $b->created->epoch <=> $a->created->epoch } @elements]); | |||||||||||||||||||||||||||
| 57 | 31 | $iterator->rewind; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 31 | return $iterator; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 11 | 1; | |||||||||||||||||||||||||||