File Coverage

blib/lib/Bootylicious/DocumentStatLoader.pm
Criterion Covered Total %
statement 28 28 100.0
branch 7 8 87.5
condition 6 9 66.6
subroutine 6 6 100.0
pod 0 1 0.0
total 47 52 90.3


line stmt bran cond sub pod time code
1             package Bootylicious::DocumentStatLoader;
2              
3 15     15   82 use strict;
  15         28  
  15         322  
4 15     15   62 use warnings;
  15         25  
  15         301  
5              
6 15     15   68 use base 'Mojo::Base';
  15         45  
  15         770  
7              
8 15     15   3449 use Bootylicious::Timestamp;
  15         41  
  15         87  
9              
10             require Carp;
11 15     15   5932 use File::stat;
  15         73009  
  15         62  
12              
13             my $TIMESTAMP_RE = qr/(\d\d\d\d)(\d?\d)(\d?\d)(?:T(\d\d):?(\d\d):?(\d\d))?/;
14              
15             __PACKAGE__->attr('path');
16              
17             sub load {
18 73     73 0 863 my $self = shift;
19 73         203 my $path = $self->path;
20              
21 73 100 66     1587 Carp::croak qq/Can't load: $!/ unless $path && -e $path;
22              
23 72         702 my ($name, $format) = ($path =~ m/\/([^\/]+)\.([^.\/]+)$/);
24              
25 72 100 66     429 Carp::croak qq/Bad file $path/ unless $name && $format;
26              
27 71         209 my $filename = join '.' => $name, $format;
28              
29 71         116 my $created;
30 71 100       823 if ($name =~ s/^($TIMESTAMP_RE)-//) {
31 67         317 $created = Bootylicious::Timestamp->new(timestamp => $1)->epoch;
32 67 50       383 return unless defined $created;
33             }
34              
35 71         248 my $modified = stat($path)->mtime;
36 71   66     10971 $created ||= $modified;
37              
38             return {
39 71         264 name => $name,
40             filename => $filename,
41             format => $format,
42             created => Bootylicious::Timestamp->new(epoch => $created),
43             modified => Bootylicious::Timestamp->new(epoch => $modified)
44             };
45             }
46              
47             1;