lib/Snig/Collection.pm

filter: Statementstmt 50.0% 32 / 64 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 61.5% 8 / 13 Podpod 0.0% 0 / 4 totaltotal 40.8% 40 / 98 CC 13 SCAR 29.1
CC
13
Cov
41%
__ANON__
42.0
write_index
30.0
resize_images
12.0
CRAP 18.4
« lib/Snig/Image.pm ↑ Summary lib/Snig.pm »
1 2 ▶use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶no warnings "experimental::class";
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 class Snig::Collection {
6  
7 2 our $VERSION = '1.001'; # VERSION
8 # ABSTRACT: Snig Collection Class
9 # PODNAME: Snig::Collection
10  
11 2 ▶ use Path::Tiny qw(path);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶ use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶ use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶ use File::Copy qw(copy);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶ use File::Share qw(dist_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 field $sort_by :reader :param = 'created'; # TODO
18 2 field $input :reader :param;
19 2 field $name :reader :param;
20  
21 2 field %images;
22 2 field @sorted :reader;
23 2 field $zip_size;
24  
25 2 field $tt;
26  
27 0 ▶ ADJUST {
Subroutine __ANON__: not called CC=6 SCAR=37.4
28 0 ▶ $input = path($input) if !ref($input);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $input 0 0 0
29 0 $tt = Template->new(ABSOLUTE=>1, WRAPPER=>dist_file('Snig','wrapper.tt'));
30  
31 0 for my $file ( $self->input->children ) {
32 0 ▶ next unless $file->basename =~ /\.jpe?g$/i; # TODO allow other image types?
Branch: 1 branch
BranchTrueFalseTotal
unless $file->basename =~ /\.jpe?g$/iu 0 0 0
33 0 $log->debugf("Reading image %s", $file->basename);
34 0 my $image = Snig::Image->new(file => $file);
35 0 $images{$file->basename} = $image;
36 }
37  
38 0 @sorted = map { $_->[1] }
39 0 sort { $a->[0] cmp $b->[0] }
40 0 map { [ $_->$sort_by, $_ ] }
41 values %images;
42  
43 0 ▶ while (my ($i, $image) = each @sorted) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each @sorted) 0 0 0
44 0 my $prev = $i-1;
45 0 ▶ my $next = $i == $#sorted ? 0 : $i+1;
Branch: 1 branch
BranchTrueFalseTotal
$i == $#sorted ? : 0 0 0
46 0 $image->set_chain($i+1, $sorted[$prev], $sorted[$next]);
47 }
48  
49 }
50  
51 0 ▶ method resize_images($output, $th_size, $detail_size, $force = 0) {
Subroutine resize_images: not called CC=3 SCAR=24.8
Pod undocumented
52 0 $log->infof("Resizing %i images", scalar @sorted);
53 0 for my $img (@sorted) {
54 0 $img->resize($output, $th_size, $detail_size, $force);
55 }
56 0 print "\n";
57 }
58  
59 0 ▶ method write_html_pages( $output ) {
Subroutine write_html_pages: not called CC=2 SCAR=17.9
Pod undocumented
60 0 $log->infof("Writing %i html pages", scalar @sorted);
61 0 for my $img (@sorted) {
62 0 $img->write_html_page($tt, $output, $self);
63 }
64 }
65  
66 0 ▶ method write_index( $output, $force_zip = 0 ) {
Subroutine write_index: not called CC=5 SCAR=34.0
Pod undocumented
67 0 my $zip_file = $self->zip_file($output);
68 0 $log->infof("Generating zip archive %s and index", $zip_file);
69 0 copy(dist_file('Snig','snig.css'), $output);
70  
71 0 ▶ if (!$zip_file->is_file || $force_zip ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $zip_file->is_file or $force_zip) 0 0 0
Condition0%0/3
not $zip_file->is_file or $force_zip
l!l&&r!l&&!r
000
MC/DC0%0/2
not $zip_file->is_file or $force_zip
not $zip_file->is_file $force_zip
Truth table0%0/3
not(A) or B
A= not $zip_file->is_fileB= $force_zip
ABresult
1X1
011
000
72 0 system('zip', '-r', $zip_file->stringify, $input->stringify);
73 }
74  
75 0 ▶ $tt->process(dist_file('Snig','index.tt'), {
Branch: 1 branch
BranchTrueFalseTotal
$tt->process(dist_file("Snig", "index.tt"), {"collection", {"name", $name, "images", \@sorted, "zip_file", $zip_file->basename, "zip_size", $zip_file->size_human({"format", "si"})}, "version", "Snig"->VERSION}, $output->child("index.html")->stringify) or die $tt->error 0 0 0
76 collection=> {
77 name => $name,
78 images => \@sorted,
79 zip_file => $zip_file->basename,
80 zip_size => $zip_file->size_human( {format => "si"} ),
81 },
82 version => Snig->VERSION,
83 }, $output->child('index.html')->stringify) || die $tt->error;
84 }
85  
86 0 ▶ method zip_file($output) {
Subroutine zip_file: not called CC=1 SCAR=6.9
Pod undocumented
87 0 my $dir = lc($output->basename);
88 0 return $output->child($dir.'.zip');
89 }
90  
91 }
92  
93 __END__
« lib/Snig/Image.pm ↑ Summary lib/Snig.pm »