Server/Image.pm

filter: Statementstmt 88.8% 16 / 18 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 91.6% 22 / 24 CC 1 SCAR 0.5
CC
1
Cov
89%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Server.pm ↑ Summary
1 package Net::DPAP::Server::Image;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use base qw( Class::Accessor::Fast );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use File::Basename qw( basename );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Image::Info;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 0 ▶use Image::Imlib2;
Subroutine BEGIN: called CC=1 SCAR=2.6
8 use Perl6::Slurp;
9 use File::Temp;
10  
11 __PACKAGE__->mk_accessors(qw(
12 file
13 dmap_itemid dmap_itemname dmap_itemkind dmap_containeritemid
14  
15 dpap_imagefilename dpap_aspectratio dpap_imagefilesize dpap_creationdate
16 ));
17  
18 sub new_from_file {
19 my $class = shift;
20 my $file = shift;
21 my $self = $class->new({ file => $file });
22 #print "Adding $file\n";
23  
24 my @stat = stat $file;
25 my $info = Image::Info::image_info( $file );
26 $self->file( $file );
27 $self->dmap_itemid( $stat[1] ); # the inode should be good enough
28 $self->dmap_containeritemid( 0+$self );
29  
30 $self->dpap_imagefilename( basename $file );
31 $self->dpap_aspectratio( $info->{width} / $info->{height} );
32 $self->dpap_imagefilesize( $stat[7] );
33 $self->dpap_creationdate( $stat[10] );
34 $self->dmap_itemname( basename $file, qw( .jpeg .jpg ) );
35 $self->dmap_itemkind( 3 );
36  
37 return $self;
38 }
39  
40 sub dpap_hires {
41 my $self = shift;
42 scalar slurp $self->file;
43 }
44  
45 sub dpap_thumb {
46 my $self = shift;
47 my $image = Image::Imlib2->load( $self->file );
48 my $thumbnail = $image->create_scaled_image( 240, 0 );
49 $thumbnail->image_set_format("jpeg");
50 my $file = File::Temp->new;
51 $thumbnail->save( $file->filename );
52 return scalar slurp $file->filename;
53 }
54  
55  
56 1;
« Server.pm ↑ Summary