| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Bootylicious::FileIteratorLoader; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 14 |  |  | 14 |  | 489 | use strict; | 
|  | 14 |  |  |  |  | 28 |  | 
|  | 14 |  |  |  |  | 315 |  | 
| 4 | 14 |  |  | 14 |  | 57 | use warnings; | 
|  | 14 |  |  |  |  | 28 |  | 
|  | 14 |  |  |  |  | 276 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 14 |  |  | 14 |  | 60 | use base 'Mojo::Base'; | 
|  | 14 |  |  |  |  | 25 |  | 
|  | 14 |  |  |  |  | 2947 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | __PACKAGE__->attr('element_class'); | 
| 9 |  |  |  |  |  |  | __PACKAGE__->attr('filter'); | 
| 10 |  |  |  |  |  |  | __PACKAGE__->attr('root'); | 
| 11 |  |  |  |  |  |  | __PACKAGE__->attr('path'); | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 14 |  |  | 14 |  | 52715 | use Mojo::ByteStream; | 
|  | 14 |  |  |  |  | 776349 |  | 
|  | 14 |  |  |  |  | 614 |  | 
| 14 | 14 |  |  | 14 |  | 4162 | use Mojo::Loader qw(load_class); | 
|  | 14 |  |  |  |  | 182326 |  | 
|  | 14 |  |  |  |  | 670 |  | 
| 15 | 14 |  |  | 14 |  | 2330 | use Bootylicious::Iterator; | 
|  | 14 |  |  |  |  | 34 |  | 
|  | 14 |  |  |  |  | 95 |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | sub files { | 
| 18 | 58 |  |  | 58 | 0 | 112 | my $self = shift; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 58 |  |  |  |  | 210 | my $root = $self->root; | 
| 21 | 58 |  |  |  |  | 346 | my $path = $self->path; | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 58 | 100 |  |  |  | 3063 | return glob $root ? "$root/*" : "$path*"; | 
| 24 |  |  |  |  |  |  | } | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | sub create_element { | 
| 27 | 93 |  |  | 93 | 0 | 178 | my $self = shift; | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 93 |  |  |  |  | 297 | load_class($self->element_class); | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 93 |  |  |  |  | 1683 | return $self->element_class->new; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | sub load { | 
| 35 | 58 |  |  | 58 | 0 | 3857 | my $self     = shift; | 
| 36 | 58 |  |  |  |  | 114 | my $iterator = shift; | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 58 |  | 66 |  |  | 351 | $iterator ||= Bootylicious::Iterator->new; | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 58 |  |  |  |  | 196 | my $filter = $self->filter; | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 58 |  |  |  |  | 159 | my @elements = (); | 
| 43 | 58 |  |  |  |  | 218 | foreach my $file ($self->files) { | 
| 44 | 113 |  |  |  |  | 2338 | $file = Mojo::ByteStream->new($file)->decode('UTF-8')->to_string; | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 113 |  |  |  |  | 9692 | my $basename = File::Basename::basename($file); | 
| 47 | 113 | 100 | 66 |  |  | 1243 | next if $filter && $basename !~ m/$filter/; | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 93 |  |  |  |  | 317 | my $element = $self->create_element; | 
| 50 | 93 |  |  |  |  | 892 | $element->load($file); | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 93 |  |  |  |  | 243 | push @elements, $element; | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | $iterator->elements( | 
| 56 | 58 |  |  |  |  | 681 | [sort { $b->created->epoch <=> $a->created->epoch } @elements]); | 
|  | 55 |  |  |  |  | 277 |  | 
| 57 | 58 |  |  |  |  | 627 | $iterator->rewind; | 
| 58 |  |  |  |  |  |  |  | 
| 59 | 58 |  |  |  |  | 331 | return $iterator; | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | 1; |