Khonsu/Image.pm

filter: Statementstmt 100% 23 / 23 Branchbran 100% 2 / 2 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 85.0% 34 / 40 CC 4 SCAR 9.2
CC
4
Cov
93%
_identify_type
4.0
BEGIN
1.0
attributes
1.0
CRAP 2.5
« Khonsu/File.pm ↑ Summary Khonsu/Form/Field.pm »
1 package Khonsu::Image;
2  
3 3 ▶use parent 'Khonsu::Ra';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 sub attributes {
6 2 ▶ my $a = shift;
Subroutine attributes: called CC=1 SCAR=0.0
Pod undocumented
7 return (
8 image => {$a->RW},
9 mime => {$a->RW, $a->STR},
10 valid_mime => {$a->RW, $a->HR, default => sub {{
11 2 ▶ jpeg => 'image_jpeg',
Subroutine __ANON__: called CC=1 SCAR=0.0
12 tiff => 'image_tiff',
13 pnm => 'image_pnm',
14 png => 'image_png',
15 gif => 'image_gif'
16 }}},
17 2 $a->POINTS
18 );
19 }
20  
21 sub add {
22 4 ▶ my ($self, $file, %attributes) = @_;
Subroutine add: called CC=1 SCAR=0.0
Pod undocumented
23 4 $self->set_attributes(%attributes);
24 4 my $type = $self->_identify_type();
25 4 my $image = $file->pdf->$type($self->image);
26 4 my %points = $self->get_points();
27 4 my $photo = $file->page->current->gfx;
28 $photo->image(
29 $image,
30 $points{x}, $points{y}, $points{w}, $points{h}
31 4 );
32 4 return $file;
33 }
34  
35 sub _identify_type {
36 4 ▶ my ($self) = @_;
Subroutine _identify_type: called CC=4 SCAR=14.0
37 4 ▶ if (!$self->mime && !ref $self->image) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->mime or ref $self->image) 2 2 4
Condition66%2/3
$self->mime or ref $self->image
l!l&&r!l&&!r
202
MC/DC50%1/2
$self->mime or ref $self->image
$self->mime ref $self->image
Truth table66%2/3
A or B
A= $self->mimeB= ref $self->image
ABresult
1X1
011
000
38 2 my $reg = sprintf '\.(%s)$', join ("|", keys %{$self->valid_mime});
39 2 $self->image =~ m/$reg/;
40 2 my $m = $1;
41 2 ▶ $self->mime($m || 'png');
Condition50%1/2
$m || 'png'
l!l
20
MC/DC0%0/1
$m || 'png'
$m
Truth table50%1/2
A
A= $m
Aresult
11
00
42 }
43 4 return $self->valid_mime->{$self->mime};
44 }
45  
46 3 1;
« Khonsu/File.pm ↑ Summary Khonsu/Form/Field.pm »