| 1 | package App::ZofCMS::Plugin::DirTreeBrowse; | ||||||||||||||||||||
| 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 | |||||||||||||||||||||
| 6 | 1 | our $VERSION = '1.001010'; # VERSION | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 1 | ▶ | use base 'App::ZofCMS::Plugin::Base'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use File::Glob (qw/bsd_glob/); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use HTML::Template; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 0 | ▶ | sub _key { 'plug_dir_tree' } | ||||||||||||||||||
|
Subroutine
_key: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 13 | 0 | ▶ | sub _defaults { qw(q_name dir_tree t_prefix dir_tree_ ) } | ||||||||||||||||||
|
Subroutine
_defaults: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 14 | 0 | ▶ | sub _do { | ||||||||||||||||||
|
Subroutine
_do: not called CC=8 SCAR=42.8
| |||||||||||||||||||||
| 15 | 0 | my ( $self, $conf, $template, $query ) = @_; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 0 | my $path = $query->{ $conf->{q_name} }; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | defined $path | ||||||||||||||||||||
| 20 | 0 | ▶ | or $path = $conf->{start}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 0 | $path =~ s{^\s*/|\.\.}{}g; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 0 | my $back_link = $path; | |||||||||||||||||||
| 25 | 0 | $back_link =~ s{/[^/]*$}{}; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 0 | my $list = $self->_get_file_list( $path ); | |||||||||||||||||||
| 28 | 0 | ▶ | if ( $conf->{re} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | 0 | @$list = grep $_->{path} =~ /$conf->{re}/, @$list; | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 0 | my $display_path = $path; | |||||||||||||||||||
| 33 | 0 | $display_path =~ s|^\Q$conf->{start}\E/?||; | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | ▶ | if ( $conf->{display_path_separator} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 0 | $display_path =~ s|/|$conf->{display_path_separator}|g; | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 0 | my $t_p = $conf->{t_prefix}; | |||||||||||||||||||
| 40 | 0 | $template->{t}{$t_p . 'path'} = $display_path; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | ▶ | if ( defined $conf->{auto_html} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 0 | my $t = HTML::Template->new_scalar_ref( \ _get_template() ); | |||||||||||||||||||
| 44 | 0 | for ( @$list ) { | |||||||||||||||||||
| 45 | 0 | $_->{page} = $query->{dir} . $query->{page}; | |||||||||||||||||||
| 46 | 0 | $_->{q_name} = $conf->{q_name}; | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | $t->param( | ||||||||||||||||||||
| 49 | q_name => $conf->{q_name}, | ||||||||||||||||||||
| 50 | page => $query->{dir} . $query->{page}, | ||||||||||||||||||||
| 51 | class => $conf->{auto_html}, | ||||||||||||||||||||
| 52 | 0 | ▶ | dir_tree_list => $list, | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | ( $back_link eq $path ? () : ( dir_tree_back => $back_link ) ), | ||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||
| 55 | 0 | $template->{t}{$t_p . 'auto'} = $t->output; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | else { | ||||||||||||||||||||
| 58 | 0 | $template->{t}{$t_p . 'list'} = $list; | |||||||||||||||||||
| 59 | 0 | ▶ | unless ( $back_link eq $path ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 0 | $template->{t}{$t_p . 'back'} = $back_link; | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 0 | ▶ | sub _get_file_list { | ||||||||||||||||||
|
Subroutine
_get_file_list: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 66 | 0 | my ( $self, $path ) = @_; | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 0 | ▶ | my @path = grep { defined and length } split '/', $path; | ||||||||||||||||||
|
Condition0%0/3
defined $_ && length $_
MC/DC0%0/2
defined $_ && length $_
defined $_
length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||
| 69 | 0 | my $glob = join '/', @path; | |||||||||||||||||||
| 70 | 0 | $glob .= '/*'; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 0 | ▶ | my @files = map +{ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | name => (split '/')[-1], | ||||||||||||||||||||
| 74 | path => $_, | ||||||||||||||||||||
| 75 | ( | ||||||||||||||||||||
| 76 | -f $_ ? ( is_file => 1 ) : () | ||||||||||||||||||||
| 77 | ) | ||||||||||||||||||||
| 78 | }, bsd_glob $glob; | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 0 | return \@files; | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 0 | ▶ | sub _get_template { | ||||||||||||||||||
|
Subroutine
_get_template: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 84 | 0 | return <<'END'; | |||||||||||||||||||
| 85 | <ul class="<tmpl_var name='class'>"> | ||||||||||||||||||||
| 86 | <tmpl_if name="dir_tree_back"><li><a href="/index.pl?page=<tmpl_var name='page'>&<tmpl_var name='q_name'>=<tmpl_var escape='html' name='dir_tree_back'>">UP</a></li></tmpl_if> | ||||||||||||||||||||
| 87 | <tmpl_loop name='dir_tree_list'> | ||||||||||||||||||||
| 88 | <li> | ||||||||||||||||||||
| 89 | <tmpl_if name="is_file"> | ||||||||||||||||||||
| 90 | <a target="_blank" href="/<tmpl_var escape='html' name='path'>"><tmpl_var escape='html' name='name'></a> | ||||||||||||||||||||
| 91 | <tmpl_else> | ||||||||||||||||||||
| 92 | <a href="/index.pl?page=<tmpl_var name='page'>&<tmpl_var name='q_name'>=<tmpl_var escape='html' name='path'>"><tmpl_var escape='html' name='name'></a> | ||||||||||||||||||||
| 93 | </tmpl_if> | ||||||||||||||||||||
| 94 | </li> | ||||||||||||||||||||
| 95 | </tmpl_loop> | ||||||||||||||||||||
| 96 | </ul> | ||||||||||||||||||||
| 97 | END | ||||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 1 | 1; | |||||||||||||||||||
| 102 | __END__ | ||||||||||||||||||||