line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Images::Service; |
2
|
7
|
|
|
7
|
|
3081
|
use Mojo::Base -base; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
47
|
|
3
|
7
|
|
|
7
|
|
823
|
use 5.20.0; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
200
|
|
4
|
7
|
|
|
7
|
|
24
|
use experimental 'signatures'; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
39
|
|
5
|
7
|
|
|
7
|
|
662
|
use IO::All; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
74
|
|
6
|
7
|
|
|
7
|
|
385
|
use Imager; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
48
|
|
7
|
7
|
|
|
7
|
|
267
|
use Mojo::URL; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
58
|
|
8
|
7
|
|
|
7
|
|
122
|
use Mojo::Path; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
35
|
|
9
|
7
|
|
|
7
|
|
1826
|
use Mojolicious::Plugin::Images::Util ':all'; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
1222
|
|
10
|
7
|
|
|
7
|
|
3038
|
use Mojolicious::Plugin::Images::Transformer; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
65
|
|
11
|
7
|
|
|
7
|
|
202
|
use Mojo::Util 'camelize'; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
8960
|
|
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
|
3152
|
sub url($self, $id) { |
|
12
|
50
|
|
|
|
26
|
|
|
12
|
|
|
|
|
16
|
|
|
12
|
|
|
|
|
14
|
|
|
12
|
|
|
|
|
12
|
|
18
|
12
|
100
|
|
|
|
36
|
my $fname |
19
|
|
|
|
|
|
|
= check_id($id) . $self->suffix . ($self->ext ? '.' . $self->ext : ''); |
20
|
11
|
|
|
|
|
438
|
my $fpath = Mojo::Path->new($fname)->leading_slash(0); |
21
|
11
|
|
|
|
|
959
|
my $url = Mojo::URL->new($self->url_prefix); |
22
|
11
|
|
|
|
|
1667
|
$url->path($url->path->trailing_slash(1)->merge($fpath)->canonicalize); |
23
|
11
|
|
|
|
|
4030
|
$url; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
47
|
50
|
|
47
|
1
|
15436
|
sub canonpath($self, $id) { |
|
47
|
50
|
|
|
|
105
|
|
|
47
|
|
|
|
|
54
|
|
|
47
|
|
|
|
|
51
|
|
|
47
|
|
|
|
|
36
|
|
27
|
47
|
|
|
|
|
129
|
$id = check_id($id); |
28
|
44
|
100
|
|
|
|
1159
|
my $fname = $id . $self->suffix . ($self->ext ? '.' . $self->ext : ''); |
29
|
44
|
|
|
|
|
2036
|
io->catfile(check_dir($self->dir, $self->controller->app), $fname) |
30
|
|
|
|
|
|
|
->canonpath; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
12
|
50
|
|
12
|
1
|
6814
|
sub exists ($self, $id) { |
|
12
|
50
|
|
|
|
31
|
|
|
12
|
|
|
|
|
19
|
|
|
12
|
|
|
|
|
20
|
|
|
12
|
|
|
|
|
18
|
|
34
|
12
|
|
|
|
|
26
|
io($self->canonpath($id))->exists; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
11
|
50
|
|
11
|
1
|
5748
|
sub read ($self, $id) { |
|
11
|
50
|
|
|
|
34
|
|
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
18
|
|
|
11
|
|
|
|
|
12
|
|
38
|
6
|
50
|
|
|
|
1783
|
Imager::->new( |
39
|
|
|
|
|
|
|
file => $self->canonpath(check_id($id)), |
40
|
11
|
|
|
|
|
35
|
%{$self->read_options || {}} |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
1
|
50
|
|
1
|
|
19
|
sub _trans($self, $id, $img) { |
|
1
|
50
|
|
|
|
4
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
46
|
1
|
|
|
|
|
30
|
my $trans = $self->transform; |
47
|
1
|
|
|
|
|
7
|
my $new; |
48
|
1
|
|
|
|
|
16
|
my %args = ( |
49
|
|
|
|
|
|
|
service => $self, |
50
|
|
|
|
|
|
|
id => $id, |
51
|
|
|
|
|
|
|
controller => $self->controller, |
52
|
|
|
|
|
|
|
image => $img, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
1
|
50
|
33
|
|
|
18
|
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
|
6
|
50
|
|
6
|
1
|
36434
|
sub write($self, $id, $img) { |
|
6
|
50
|
|
|
|
20
|
|
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
10
|
|
84
|
6
|
|
|
|
|
25
|
my $canonpath = $self->canonpath($id); |
85
|
1
|
|
|
|
|
212
|
my $dir = io->file($canonpath)->filepath; |
86
|
1
|
|
|
|
|
178
|
my $new = _trans($self, $id, $img); |
87
|
|
|
|
|
|
|
|
88
|
1
|
50
|
|
|
|
3
|
io->dir($dir)->mkpath unless io->dir($dir)->exists; |
89
|
1
|
50
|
|
|
|
141
|
$new->write(file => $canonpath, %{$self->write_options || {}}) |
|
1
|
50
|
|
|
|
40
|
|
90
|
|
|
|
|
|
|
or die Imager::->errstr; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |