| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Test::CGI::Multipart::Gen::Image; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
928
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
37
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
87
|
|
|
6
|
1
|
|
|
1
|
|
7
|
use Readonly; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
40
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use Test::CGI::Multipart; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
10
|
|
|
8
|
1
|
|
|
1
|
|
367
|
use GD::Simple; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use version; our $VERSION = qv('0.0.3'); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Module implementation here |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Test::CGI::Multipart->register_callback( |
|
15
|
|
|
|
|
|
|
callback => sub { |
|
16
|
|
|
|
|
|
|
my $hashref = shift; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my %to_delete; |
|
19
|
|
|
|
|
|
|
return $hashref if exists $hashref->{value}; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# If the MIME type is not explicitly image/* its not ours. |
|
22
|
|
|
|
|
|
|
return $hashref if not exists $hashref->{type}; |
|
23
|
|
|
|
|
|
|
return $hashref if $hashref->{type} !~ m{\Aimage/(\w+)\z}xms; |
|
24
|
|
|
|
|
|
|
my $type = $1; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# get dimensions |
|
27
|
|
|
|
|
|
|
croak "no width specified" if not exists $hashref->{width}; |
|
28
|
|
|
|
|
|
|
my $width = $hashref->{width}; |
|
29
|
|
|
|
|
|
|
$to_delete{width} = 1; |
|
30
|
|
|
|
|
|
|
croak "no height specified" if not exists $hashref->{height}; |
|
31
|
|
|
|
|
|
|
my $height = $hashref->{height}; |
|
32
|
|
|
|
|
|
|
$to_delete{height} = 1; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $image = GD::Simple->new($width, $height); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
croak "no instructions specified" |
|
37
|
|
|
|
|
|
|
if not exists $hashref->{instructions}; |
|
38
|
|
|
|
|
|
|
croak "intructions not a list" |
|
39
|
|
|
|
|
|
|
if ref $hashref->{instructions} ne 'ARRAY'; |
|
40
|
|
|
|
|
|
|
my @instructions = @{$hashref->{instructions}}; |
|
41
|
|
|
|
|
|
|
$to_delete{instructions} = 1; |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
foreach my $instr (@instructions) { |
|
44
|
|
|
|
|
|
|
my ($cmd, @args) = @$instr; |
|
45
|
|
|
|
|
|
|
eval {$image->$cmd(@args)}; |
|
46
|
|
|
|
|
|
|
if ($@) { |
|
47
|
|
|
|
|
|
|
warn "GD: $@"; |
|
48
|
|
|
|
|
|
|
return $hashref; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$hashref->{value} = eval {$image->$type}; |
|
53
|
|
|
|
|
|
|
if ($@) { |
|
54
|
|
|
|
|
|
|
warn "GD: $@"; |
|
55
|
|
|
|
|
|
|
delete $hashref->{value}; |
|
56
|
|
|
|
|
|
|
return $hashref; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
foreach my $del (keys %to_delete) { |
|
60
|
|
|
|
|
|
|
delete $hashref->{$del}; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
return $hashref; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
|
68
|
|
|
|
|
|
|
__END__ |