| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 44 | 0 | my $prev = $i-1; | |||||||||||||||||||||||||||
| 45 | 0 | ▶ | my $next = $i == $#sorted ? 0 : $i+1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
not $zip_file->is_file or $force_zip
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
| |||||||||||||||||||||||||||||
| 72 | 0 | system('zip', '-r', $zip_file->stringify, $input->stringify); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $tt->process(dist_file('Snig','index.tt'), { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||