line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Images::Service; |
2
|
7
|
|
|
7
|
|
3021
|
use Mojo::Base -base; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
47
|
|
3
|
7
|
|
|
7
|
|
765
|
use 5.20.0; |
|
7
|
|
|
|
|
21
|
|
|
7
|
|
|
|
|
206
|
|
4
|
7
|
|
|
7
|
|
23
|
use experimental 'signatures'; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
40
|
|
5
|
7
|
|
|
7
|
|
677
|
use IO::All; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
65
|
|
6
|
7
|
|
|
7
|
|
406
|
use Imager; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
103
|
|
7
|
7
|
|
|
7
|
|
310
|
use Mojo::URL; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
66
|
|
8
|
7
|
|
|
7
|
|
149
|
use Mojo::Path; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
33
|
|
9
|
7
|
|
|
7
|
|
1928
|
use Mojolicious::Plugin::Images::Util ':all'; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
1082
|
|
10
|
7
|
|
|
7
|
|
2865
|
use Mojolicious::Plugin::Images::Transformer; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
61
|
|
11
|
7
|
|
|
7
|
|
192
|
use Mojo::Util 'camelize'; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
10173
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has [qw(namespace url_prefix ext dir suffix write_options read_options)]; |
14
|
|
|
|
|
|
|
has 'transform'; |
15
|
|
|
|
|
|
|
has 'controller'; |
16
|
|
|
|
|
|
|
|
17
|
12
|
50
|
|
12
|
1
|
3199
|
sub url($self, $id) { |
|
12
|
50
|
|
|
|
29
|
|
|
12
|
|
|
|
|
16
|
|
|
12
|
|
|
|
|
18
|
|
|
12
|
|
|
|
|
14
|
|
18
|
12
|
100
|
|
|
|
32
|
my $fname |
19
|
|
|
|
|
|
|
= check_id($id) . $self->suffix . ($self->ext ? '.' . $self->ext : ''); |
20
|
11
|
|
|
|
|
403
|
my $fpath = Mojo::Path->new($fname)->leading_slash(0); |
21
|
11
|
|
|
|
|
922
|
my $url = Mojo::URL->new($self->url_prefix); |
22
|
11
|
|
|
|
|
1625
|
$url->path($url->path->trailing_slash(1)->merge($fpath)->canonicalize); |
23
|
11
|
|
|
|
|
3865
|
$url; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
49
|
50
|
|
49
|
1
|
13557
|
sub canonpath($self, $id) { |
|
49
|
50
|
|
|
|
108
|
|
|
49
|
|
|
|
|
53
|
|
|
49
|
|
|
|
|
52
|
|
|
49
|
|
|
|
|
51
|
|
27
|
49
|
|
|
|
|
131
|
$id = check_id($id); |
28
|
46
|
100
|
|
|
|
1142
|
my $fname = $id . $self->suffix . ($self->ext ? '.' . $self->ext : ''); |
29
|
46
|
|
|
|
|
2072
|
io->catfile(check_dir($self->dir, $self->controller->app), $fname) |
30
|
|
|
|
|
|
|
->canonpath; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
12
|
50
|
|
12
|
1
|
5889
|
sub exists ($self, $id) { |
|
12
|
50
|
|
|
|
29
|
|
|
12
|
|
|
|
|
17
|
|
|
12
|
|
|
|
|
14
|
|
|
12
|
|
|
|
|
13
|
|
34
|
12
|
|
|
|
|
21
|
io($self->canonpath($id))->exists; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
11
|
50
|
|
11
|
1
|
5940
|
sub read ($self, $id) { |
|
11
|
50
|
|
|
|
35
|
|
|
11
|
|
|
|
|
18
|
|
|
11
|
|
|
|
|
15
|
|
|
11
|
|
|
|
|
16
|
|
38
|
6
|
50
|
|
|
|
1071
|
Imager::->new( |
39
|
|
|
|
|
|
|
file => $self->canonpath(check_id($id)), |
40
|
11
|
|
|
|
|
29
|
%{$self->read_options || {}} |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
1
|
50
|
|
1
|
|
14
|
sub _trans($self, $id, $img) { |
|
1
|
50
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1
|
|
46
|
1
|
|
|
|
|
27
|
my $trans = $self->transform; |
47
|
1
|
|
|
|
|
5
|
my $new; |
48
|
1
|
|
|
|
|
15
|
my %args = ( |
49
|
|
|
|
|
|
|
service => $self, |
50
|
|
|
|
|
|
|
id => $id, |
51
|
|
|
|
|
|
|
controller => $self->controller, |
52
|
|
|
|
|
|
|
image => $img, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
1
|
50
|
33
|
|
|
15
|
if (ref $trans eq 'CODE') { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
plugin_log($self->controller->app, "Transformation to cb with id $id"); |
57
|
0
|
|
|
|
|
0
|
$new = $trans->(Mojolicious::Plugin::Images::Transformer->new(%args)); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
elsif (ref $trans eq 'ARRAY') { |
61
|
0
|
|
|
|
|
0
|
$new = $img; |
62
|
0
|
|
|
|
|
0
|
my @arr = @$trans; |
63
|
0
|
|
|
|
|
0
|
while (@arr) { |
64
|
0
|
|
|
|
|
0
|
my ($act, $args) = (shift @arr, shift @arr); |
65
|
0
|
|
|
|
|
0
|
$new = $new->$act(%$args); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
elsif ($trans && $trans =~ /^([\w\-:]+)\#([\w]+)$/) { |
70
|
0
|
|
|
|
|
0
|
my ($class, $action) = (camelize($1), $2); |
71
|
0
|
0
|
|
|
|
0
|
$class = $self->namespace . "::$class" if $self->namespace; |
72
|
0
|
|
|
|
|
0
|
plugin_log($self->controller->app, |
73
|
|
|
|
|
|
|
"Transformation to class $class and action $action with id $id"); |
74
|
0
|
|
|
|
|
0
|
$new = $class->new(%args)->$action; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
else { |
78
|
1
|
|
|
|
|
2
|
$new = $img; |
79
|
|
|
|
|
|
|
} |
80
|
1
|
|
|
|
|
3
|
return $new; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
8
|
50
|
|
8
|
1
|
61
|
sub abs_path($self, $id) { |
|
8
|
50
|
|
|
|
24
|
|
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
12
|
|
84
|
8
|
|
|
|
|
24
|
my $canonpath = $self->canonpath($id); |
85
|
3
|
100
|
|
|
|
583
|
return $canonpath if io($canonpath)->is_absolute; |
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
113
|
return $self->controller->app->home->rel_file($canonpath); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
6
|
50
|
|
6
|
1
|
37731
|
sub write($self, $id, $img) { |
|
6
|
50
|
|
|
|
24
|
|
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
9
|
|
91
|
6
|
|
|
|
|
30
|
my $abs_path = $self->abs_path($id); |
92
|
1
|
|
|
|
|
141
|
my $dir = io->file($abs_path)->filepath; |
93
|
1
|
|
|
|
|
188
|
my $new = _trans($self, $id, $img); |
94
|
|
|
|
|
|
|
|
95
|
1
|
50
|
|
|
|
2
|
io->dir($dir)->mkpath unless io->dir($dir)->exists; |
96
|
1
|
50
|
|
|
|
197
|
$new->write(file => $abs_path, %{$self->write_options || {}}) |
|
1
|
50
|
|
|
|
39
|
|
97
|
|
|
|
|
|
|
or die Imager::->errstr; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |