line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::TemplateCMD::Command::List; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Created on: 2008-03-26 13:44:05 |
4
|
|
|
|
|
|
|
# Create by: ivanw |
5
|
|
|
|
|
|
|
# $Id$ |
6
|
|
|
|
|
|
|
# $Revision$, $HeadURL$, $Date$ |
7
|
|
|
|
|
|
|
# $Revision$, $Source$, $Date$ |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
1568
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
49
|
|
10
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
47
|
|
11
|
2
|
|
|
2
|
|
334
|
use version; |
|
2
|
|
|
|
|
1510
|
|
|
2
|
|
|
|
|
11
|
|
12
|
2
|
|
|
2
|
|
124
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
106
|
|
13
|
2
|
|
|
2
|
|
455
|
use List::MoreUtils qw/uniq/; |
|
2
|
|
|
|
|
10907
|
|
|
2
|
|
|
|
|
13
|
|
14
|
2
|
|
|
2
|
|
2036
|
use Data::Dumper qw/Dumper/; |
|
2
|
|
|
|
|
5918
|
|
|
2
|
|
|
|
|
116
|
|
15
|
2
|
|
|
2
|
|
366
|
use English qw/ -no_match_vars /; |
|
2
|
|
|
|
|
1367
|
|
|
2
|
|
|
|
|
11
|
|
16
|
2
|
|
|
2
|
|
626
|
use base qw/App::TemplateCMD::Command/; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1033
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = version->new('0.6.12'); |
19
|
|
|
|
|
|
|
our @EXPORT_OK = qw//; |
20
|
|
|
|
|
|
|
our %EXPORT_TAGS = (); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub process { |
23
|
0
|
|
|
0
|
1
|
|
my ($self, $cmd, %option) = @_; |
24
|
0
|
|
|
|
|
|
my $out = ''; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my $filter = shift @{$option{files}}; |
|
0
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $path = $cmd->config->{path}; |
28
|
0
|
|
|
|
|
|
my @path = grep {-d $_} split /:/, $path; |
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my @files = $cmd->list_templates(); |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my @templates = uniq sort map {$_->{file}} @files; |
|
0
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
if ($filter) { |
35
|
0
|
|
|
|
|
|
@templates = grep {/$filter/} @templates; |
|
0
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
0
|
|
|
|
$option{columns} ||= 6; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $files_per_col = @templates / $option{columns}; |
41
|
0
|
0
|
|
|
|
|
$files_per_col = $files_per_col == int $files_per_col ? $files_per_col : int $files_per_col + 1; |
42
|
0
|
|
|
|
|
|
my @columns; |
43
|
|
|
|
|
|
|
my @max; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
for my $row ( 0 .. $files_per_col - 1 ) { |
46
|
0
|
|
|
|
|
|
for my $col ( 0 .. $option{columns} - 1 ) { |
47
|
0
|
0
|
|
|
|
|
next if !$templates[$row * $option{columns} + $col]; |
48
|
0
|
|
|
|
|
|
push @{$columns[$col]}, $templates[$row * $option{columns} + $col]; |
|
0
|
|
|
|
|
|
|
49
|
0
|
|
0
|
|
|
|
$max[$col] ||= 1; |
50
|
0
|
0
|
|
|
|
|
$max[$col] = length $templates[$row * $option{columns} + $col] if length $templates[$row * $option{columns} + $col] > $max[$col]; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
for my $row ( 0 .. $files_per_col -1 ) { |
55
|
0
|
|
|
|
|
|
for my $col ( 0 .. $option{columns} - 1 ) { |
56
|
0
|
0
|
|
|
|
|
next if !$columns[$col][$row]; |
57
|
0
|
|
|
|
|
|
$out .= $columns[$col][$row] . ' ' x ($max[$col] + 1 - length $columns[$col][$row]); |
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
|
$out .= "\n"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return $out; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub help { |
66
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return <<"HELP"; |
69
|
|
|
|
|
|
|
$0 list [filter] |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
filter An optional regular expression to show only templates that match. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Lists all the templates that can be found, optionally limited by the regular |
74
|
|
|
|
|
|
|
expression filter. |
75
|
|
|
|
|
|
|
HELP |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |