ZofCMS/Plugin/FileTypeIcon.pm

filter: Statementstmt 28.5% 14 / 49 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 4 / 8 Podpod 0.0% 0 / 1 totaltotal 23.0% 18 / 78 CC 12 SCAR 41.0
CC
12
Cov
20%
_do
110.0
make_icon_name
12.0
_key
2.0
CRAP 60.2
« ZofCMS/Plugin/GooglePageRank.pm ↑ Summary ZofCMS/Plugin/FeatureSuggestionBox.pm »
1 package App::ZofCMS::Plugin::FileTypeIcon;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '1.001010'; # VERSION
8  
9 1 ▶use base 'App::ZofCMS::Plugin::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub _key { 'plug_file_type_icon' }
Subroutine _key: not called CC=1 SCAR=6.9
12 0 ▶sub _defaults {
Subroutine _defaults: not called CC=1 SCAR=6.9
13 return (
14 0 resource => 'pics/fileicons/',
15 prefix => 'fileicon_',
16 as_arrayref => 0,
17 only_path => 0,
18 icon_width => 16,
19 icon_height => 16,
20 xhtml => 0,
21 );
22 }
23 0 ▶sub _do {
Subroutine _do: not called CC=10 SCAR=47.0
24 0 my ( $self, $conf, $t, $q, $config ) = @_;
25  
26 return
27 0 ▶ unless defined $conf->{files};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $conf->{"files"} 0 0 0
28  
29 0 ▶ unless ( ref $conf->{files} eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $conf->{"files"} eq "ARRAY") 0 0 0
30 0 $conf->{files} = [ $conf->{files} ];
31 }
32  
33 0 my $counter = 0;
34 0 ▶ my $tag_end = $conf->{xhtml} ? '/' : '';
Branch: 1 branch
BranchTrueFalseTotal
$conf->{'xhtml'} ? : 0 0 0
35 0 for ( @{ $conf->{files} } ) {
36 0 my $key_name;
37 0 my $file = $_;
38 0 ▶ if ( ref eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq "CODE") 0 0 0
39 0 $_ = $_->( $t, $q, $config );
40 }
41  
42 0 ▶ if ( ref eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq 'HASH') { } 0 0 0
43 0 ( $file, $key_name ) = %$_;
44 }
45 else {
46 0 $key_name = "$conf->{prefix}$counter";
47 0 $counter++;
48 }
49  
50 0 my ( $icon_file, $img_alt ) = make_icon_name($conf->{resource}, $file);
51  
52 my $value = $conf->{only_path}
53 0 ▶ ? $icon_file
Branch: 1 branch
BranchTrueFalseTotal
$conf->{'only_path'} ? : 0 0 0
54 : qq|<img class="file_type_icon" src="$icon_file" width="$conf->{icon_width}" height="$conf->{icon_height}" alt="$img_alt" title="$img_alt"$tag_end>|;
55  
56 0 ▶ if ( $conf->{as_arrayref} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{'as_arrayref'}) { } 0 0 0
57 0 push @{ $t->{t}{ $conf->{prefix} } }, $value;
58 }
59 else {
60 0 $t->{t}{ $key_name } = $value;
61 }
62 }
63  
64 0 ▶ if ( ref $conf->{code_after} eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $conf->{"code_after"} eq "CODE") 0 0 0
65 0 $conf->{code_after}->( $t, $q, $config );
66 }
67 }
68  
69 0 ▶sub make_icon_name {
Subroutine make_icon_name: not called CC=3 SCAR=24.8
Pod undocumented
70 0 my ( $resource, $file ) = @_;
71 0 my ( $ext ) = $file =~ /[.]([^.]+)$/;
72 0 ▶ $ext = 'unknown'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ext 0 0 0
73 unless defined $ext;
74  
75 0 my $icon_file = File::Spec->catfile( $resource, $ext . '.png' );
76 0 ▶ if ( -e $icon_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $icon_file) { } 0 0 0
77 0 return ( $icon_file, uc($ext) . ' file' );
78 }
79 else {
80 0 $ext = 'unknown';
81 0 $icon_file = File::Spec->catfile( $resource, $ext . '.png' );
82 0 return ( $icon_file, 'Unknown file format' );
83 }
84 }
85  
86 1 1;
87 __END__
« ZofCMS/Plugin/GooglePageRank.pm ↑ Summary ZofCMS/Plugin/FeatureSuggestionBox.pm »