| 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
| |||||||||||
| 28 | |||||||||||
| 29 | 0 | ▶ | unless ( ref $conf->{files} eq 'ARRAY' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 0 | $conf->{files} = [ $conf->{files} ]; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 0 | my $counter = 0; | |||||||||
| 34 | 0 | ▶ | my $tag_end = $conf->{xhtml} ? '/' : ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 0 | for ( @{ $conf->{files} } ) { | |||||||||
| 36 | 0 | my $key_name; | |||||||||
| 37 | 0 | my $file = $_; | |||||||||
| 38 | 0 | ▶ | if ( ref eq 'CODE' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 0 | $_ = $_->( $t, $q, $config ); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | if ( ref eq 'HASH' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||