line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Images::Service; |
2
|
7
|
|
|
7
|
|
2953
|
use Mojo::Base -base; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
46
|
|
3
|
7
|
|
|
7
|
|
762
|
use 5.20.0; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
205
|
|
4
|
7
|
|
|
7
|
|
31
|
use experimental 'signatures'; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
39
|
|
5
|
7
|
|
|
7
|
|
667
|
use IO::All; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
67
|
|
6
|
7
|
|
|
7
|
|
424
|
use Imager; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
49
|
|
7
|
7
|
|
|
7
|
|
262
|
use Mojo::URL; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
60
|
|
8
|
7
|
|
|
7
|
|
130
|
use Mojo::Path; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
37
|
|
9
|
7
|
|
|
7
|
|
1856
|
use Mojolicious::Plugin::Images::Util ':all'; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
1089
|
|
10
|
7
|
|
|
7
|
|
2871
|
use Mojolicious::Plugin::Images::Transformer; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
125
|
|
11
|
7
|
|
|
7
|
|
192
|
use Mojo::Util 'camelize'; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
9149
|
|
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
|
2359
|
sub url($self, $id) { |
|
12
|
50
|
|
|
|
29
|
|
|
12
|
|
|
|
|
15
|
|
|
12
|
|
|
|
|
16
|
|
|
12
|
|
|
|
|
11
|
|
18
|
12
|
100
|
|
|
|
35
|
my $fname |
19
|
|
|
|
|
|
|
= check_id($id) . $self->suffix . ($self->ext ? '.' . $self->ext : ''); |
20
|
11
|
|
|
|
|
477
|
my $fpath = Mojo::Path->new($fname)->leading_slash(0); |
21
|
11
|
|
|
|
|
876
|
my $url = Mojo::URL->new($self->url_prefix); |
22
|
11
|
|
|
|
|
1442
|
$url->path($url->path->trailing_slash(1)->merge($fpath)->canonicalize); |
23
|
11
|
|
|
|
|
3476
|
$url; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
49
|
50
|
|
49
|
1
|
14229
|
sub canonpath($self, $id) { |
|
49
|
50
|
|
|
|
101
|
|
|
49
|
|
|
|
|
56
|
|
|
49
|
|
|
|
|
50
|
|
|
49
|
|
|
|
|
58
|
|
27
|
49
|
|
|
|
|
137
|
$id = check_id($id); |
28
|
46
|
100
|
|
|
|
1124
|
my $fname = $id . $self->suffix . ($self->ext ? '.' . $self->ext : ''); |
29
|
46
|
|
|
|
|
1840
|
io->catfile(check_dir($self->dir, $self->controller->app), $fname) |
30
|
|
|
|
|
|
|
->canonpath; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
12
|
50
|
|
12
|
1
|
6140
|
sub exists ($self, $id) { |
|
12
|
50
|
|
|
|
32
|
|
|
12
|
|
|
|
|
21
|
|
|
12
|
|
|
|
|
15
|
|
|
12
|
|
|
|
|
19
|
|
34
|
12
|
|
|
|
|
46
|
io($self->abs_path($id))->exists; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
11
|
50
|
|
11
|
1
|
5341
|
sub read ($self, $id) { |
|
11
|
50
|
|
|
|
29
|
|
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
14
|
|
|
11
|
|
|
|
|
12
|
|
38
|
6
|
50
|
|
|
|
731
|
Imager::->new( |
39
|
|
|
|
|
|
|
file => $self->abs_path(check_id($id)), |
40
|
11
|
|
|
|
|
36
|
%{$self->read_options || {}} |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
1
|
50
|
|
1
|
|
14
|
sub _trans($self, $id, $img) { |
|
1
|
50
|
|
|
|
4
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1
|
|
46
|
1
|
|
|
|
|
27
|
my $trans = $self->transform; |
47
|
1
|
|
|
|
|
5
|
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
|
|
|
17
|
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
|
|
|
|
|
2
|
return $new; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
30
|
50
|
|
30
|
1
|
95
|
sub abs_path($self, $id) { |
|
30
|
50
|
|
|
|
69
|
|
|
30
|
|
|
|
|
32
|
|
|
30
|
|
|
|
|
41
|
|
|
30
|
|
|
|
|
31
|
|
84
|
30
|
|
|
|
|
88
|
my $canonpath = $self->canonpath($id); |
85
|
16
|
100
|
|
|
|
2591
|
return $canonpath if io($canonpath)->is_absolute; |
86
|
|
|
|
|
|
|
|
87
|
3
|
|
|
|
|
289
|
return $self->controller->app->home->rel_file($canonpath); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
6
|
50
|
|
6
|
1
|
35921
|
sub write($self, $id, $img) { |
|
6
|
50
|
|
|
|
26
|
|
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
8
|
|
91
|
6
|
|
|
|
|
23
|
my $abs_path = $self->abs_path($id); |
92
|
1
|
|
|
|
|
119
|
my $dir = io->file($abs_path)->filepath; |
93
|
1
|
|
|
|
|
137
|
my $new = _trans($self, $id, $img); |
94
|
|
|
|
|
|
|
|
95
|
1
|
50
|
|
|
|
4
|
io->dir($dir)->mkpath unless io->dir($dir)->exists; |
96
|
1
|
50
|
|
|
|
133
|
$new->write(file => $abs_path, %{$self->write_options || {}}) |
|
1
|
50
|
|
|
|
38
|
|
97
|
|
|
|
|
|
|
or die Imager::->errstr; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |