line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::TT2Site::Plugin::Mapper; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1409
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
4
|
1
|
|
|
1
|
|
1073
|
use Template::Plugin; |
|
1
|
|
|
|
|
489630
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
977
|
use Text::ParseWords; |
|
1
|
|
|
|
|
1335
|
|
|
1
|
|
|
|
|
63
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use vars qw( $VERSION ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
8
|
1
|
|
|
1
|
|
4
|
use base qw( Template::Plugin ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1080
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $error = 0; |
13
|
|
|
|
|
|
|
my $map; |
14
|
|
|
|
|
|
|
my $trace; |
15
|
|
|
|
|
|
|
my $verbose; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
0
|
0
|
|
0
|
1
|
|
my $config = ref($_[-1]) eq 'HASH' ? pop(@_) : { }; |
19
|
0
|
|
|
|
|
|
my ($class, $context) = @_; |
20
|
0
|
|
|
|
|
|
my $self = {}; |
21
|
0
|
|
|
|
|
|
my $stash = $context->stash; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
$trace = $config->{trace}; |
24
|
0
|
|
|
|
|
|
$verbose = $config->{verbose}; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
bless $self, $class; # unused |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
$error = 0; |
29
|
0
|
|
|
|
|
|
my $languages = $stash->get([qw(site 0 languages 0)]); |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
|
unless ( $map ) { |
|
|
0
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $srcdir = File::Spec->catfile($stash->get('rootdir'), |
33
|
|
|
|
|
|
|
$stash->get('tmplsrc')); |
34
|
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
if ( $languages ) { |
36
|
0
|
0
|
|
|
|
|
warn("Mapper: Creating map for languages ", |
37
|
|
|
|
|
|
|
join(", ", @$languages), ".\n") if $verbose; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
foreach my $lang ( @$languages ) { |
40
|
0
|
|
|
|
|
|
my $dir = File::Spec->catfile($srcdir, $lang); |
41
|
0
|
0
|
|
|
|
|
unless ( -d $dir ) { |
42
|
0
|
0
|
|
|
|
|
warn("Mapper: Missing directory for language ", |
43
|
|
|
|
|
|
|
$lang, "\n") if $verbose; |
44
|
0
|
|
|
|
|
|
next; |
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
|
|
|
|
$map->{$lang} = $self->_do_map($dir); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
0
|
0
|
|
|
|
|
warn("Mapper: Creating site map\n") if $trace; |
51
|
0
|
|
|
|
|
|
$map = $self->_do_map($srcdir); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
$self->throw("Errors detected\n") if $error; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
elsif ( $trace ) { |
57
|
0
|
|
|
|
|
|
print STDERR ("Mapper: Reusing cached map"); |
58
|
0
|
0
|
|
|
|
|
print STDERR (" for language ", |
59
|
|
|
|
|
|
|
$stash->get([qw(site 0 lang 0)])) |
60
|
|
|
|
|
|
|
if $languages; |
61
|
0
|
|
|
|
|
|
print STDERR ("\n"); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
if ( $languages ) { |
65
|
0
|
|
|
|
|
|
$stash->set([qw(site 0 map 0)], |
66
|
|
|
|
|
|
|
$map->{$stash->get([qw(site 0 lang 0)])}); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
else { |
69
|
0
|
|
|
|
|
|
$stash->set([qw(site 0 map 0)], $map); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
################ Subroutines ################ |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub throw { |
76
|
0
|
|
|
0
|
0
|
|
my ($self, $error) = @_; |
77
|
0
|
|
|
|
|
|
die(Template::Exception->new('Mapper', $error)); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _do_map { |
81
|
0
|
|
|
0
|
|
|
my ($self, $cur) = @_; |
82
|
0
|
|
|
|
|
|
my $map = "$cur/.map"; |
83
|
0
|
|
|
|
|
|
my $m = {}; |
84
|
0
|
0
|
0
|
|
|
|
unless ( -s $map && -r _ ) { |
85
|
0
|
|
|
|
|
|
warn("Mapper: Missing: $map\n"); |
86
|
0
|
|
|
|
|
|
return $m; |
87
|
|
|
|
|
|
|
} |
88
|
0
|
0
|
|
|
|
|
warn("Mapper: Process: $map\n") if $verbose; |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
open (my $mf, "<$map") or $self->throw("$map: $!\n"); |
91
|
0
|
|
|
|
|
|
while ( <$mf> ) { |
92
|
0
|
|
|
|
|
|
chomp; |
93
|
0
|
0
|
|
|
|
|
next if /^\s*#/; |
94
|
0
|
0
|
|
|
|
|
next unless /\S/; |
95
|
0
|
|
|
|
|
|
my @w = shellwords($_); |
96
|
0
|
0
|
0
|
|
|
|
if ( $w[0] eq "title" && @w == 2 ) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
97
|
0
|
|
|
|
|
|
$m->{title} = $w[1]; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
elsif ( $w[0] eq "name" && @w == 2 ) { |
100
|
0
|
|
|
|
|
|
$m->{name} = $w[1]; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
elsif ( $w[0] eq "menu" && @w == 3 ) { |
103
|
0
|
|
0
|
|
|
|
$m->{menu} ||= []; |
104
|
0
|
|
|
|
|
|
my $tag = $w[2]; |
105
|
0
|
0
|
|
|
|
|
$tag = sprintf("menu%02d", 1+scalar(@{$m->{menu}})) |
|
0
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
if $tag !~ /^\w+$/; |
107
|
0
|
|
|
|
|
|
push(@{$m->{menu}}, $tag); |
|
0
|
|
|
|
|
|
|
108
|
0
|
0
|
|
|
|
|
if ( -f "$cur/$w[2].html" ) { |
|
|
0
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$m->{page}->{$tag}->{name} = $w[1]; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
elsif ( -d "$cur/".$w[2] ) { |
112
|
0
|
|
|
|
|
|
$m->{page}->{$tag} = { |
113
|
|
|
|
|
|
|
name => $w[1], |
114
|
0
|
|
|
|
|
|
%{$self->_do_map("$cur/$w[2]")}, |
115
|
|
|
|
|
|
|
}; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
else { |
118
|
0
|
|
|
|
|
|
$m->{page}->{$tag}->{name} = $w[1]; |
119
|
0
|
|
|
|
|
|
$m->{page}->{$tag}->{file} = $w[2]; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
else { |
123
|
0
|
|
|
|
|
|
warn("Mapper: Invalid entry in .map: $_\n"); |
124
|
0
|
|
|
|
|
|
$error++; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
$m; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |