| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DDG::Publisher::DirRole; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: The role for a directory in the publisher system |
|
3
|
|
|
|
|
|
|
$DDG::Publisher::DirRole::VERSION = '1042'; |
|
4
|
1
|
|
|
1
|
|
1319
|
use MooX::Role; |
|
|
1
|
|
|
|
|
143
|
|
|
|
1
|
|
|
|
|
4
|
|
|
5
|
1
|
|
|
1
|
|
7167
|
use DDG::Publisher::File; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
461
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
requires qw( |
|
8
|
|
|
|
|
|
|
path |
|
9
|
|
|
|
|
|
|
pages |
|
10
|
|
|
|
|
|
|
); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has key => ( |
|
14
|
|
|
|
|
|
|
is => 'ro', |
|
15
|
|
|
|
|
|
|
required => 1, |
|
16
|
|
|
|
|
|
|
); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has site => ( |
|
20
|
|
|
|
|
|
|
is => 'ro', |
|
21
|
|
|
|
|
|
|
required => 1, |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has files => ( |
|
26
|
|
|
|
|
|
|
is => 'ro', |
|
27
|
|
|
|
|
|
|
lazy => 1, |
|
28
|
|
|
|
|
|
|
builder => 1, |
|
29
|
|
|
|
|
|
|
); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _build_files { |
|
32
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
33
|
0
|
|
|
|
|
|
my %pages = %{$self->pages_coderefs}; |
|
|
0
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my @locales = $self->site->locales; |
|
35
|
0
|
|
|
|
|
|
my %files; |
|
36
|
0
|
|
|
|
|
|
for my $page (keys %pages) { |
|
37
|
0
|
|
|
|
|
|
my $code = $pages{$page}; |
|
38
|
0
|
|
|
|
|
|
for my $locale (@locales) { |
|
39
|
0
|
|
|
|
|
|
my $file = DDG::Publisher::File->new( |
|
40
|
|
|
|
|
|
|
code => $code, |
|
41
|
|
|
|
|
|
|
filebase => $page, |
|
42
|
|
|
|
|
|
|
locale => $locale, |
|
43
|
|
|
|
|
|
|
dir => $self, |
|
44
|
|
|
|
|
|
|
); |
|
45
|
0
|
|
|
|
|
|
$files{$page}->{$locale} = $file; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
} |
|
48
|
0
|
|
|
|
|
|
my $default_locale = $self->site->default_locale; |
|
49
|
0
|
|
|
|
|
|
my %statics = %{$self->statics_coderefs}; |
|
|
0
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
for my $static (keys %statics) { |
|
51
|
0
|
|
|
|
|
|
my $code = $statics{$static}; |
|
52
|
0
|
|
|
|
|
|
my $file = DDG::Publisher::File->new( |
|
53
|
|
|
|
|
|
|
code => $code, |
|
54
|
|
|
|
|
|
|
filebase => $static, |
|
55
|
|
|
|
|
|
|
locale => $default_locale, |
|
56
|
|
|
|
|
|
|
dir => $self, |
|
57
|
|
|
|
|
|
|
static => 1, |
|
58
|
|
|
|
|
|
|
); |
|
59
|
0
|
|
|
|
|
|
$files{$static} = $file; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
0
|
|
|
|
|
|
return \%files; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
has fullpath_files => ( |
|
66
|
|
|
|
|
|
|
is => 'ro', |
|
67
|
|
|
|
|
|
|
lazy => 1, |
|
68
|
|
|
|
|
|
|
builder => 1, |
|
69
|
|
|
|
|
|
|
); |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _build_fullpath_files { |
|
72
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
73
|
0
|
|
|
|
|
|
my %fullpath_files; |
|
74
|
0
|
|
|
|
|
|
for (values %{$self->files}) { |
|
|
0
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
if (ref $_ eq 'HASH') { |
|
76
|
0
|
|
|
|
|
|
for (values %{$_}) { |
|
|
0
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
die "The file ".$_->fullpath." already exist!!!" if defined $fullpath_files{$_->fullpath}; |
|
78
|
0
|
|
|
|
|
|
$fullpath_files{$_->fullpath} = $_; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
} else { |
|
81
|
0
|
0
|
|
|
|
|
die "The file ".$_->fullpath." already exist!!!" if defined $fullpath_files{$_->fullpath}; |
|
82
|
0
|
|
|
|
|
|
$fullpath_files{$_->fullpath} = $_; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
} |
|
85
|
0
|
|
|
|
|
|
return \%fullpath_files; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
has pages_coderefs => ( |
|
90
|
|
|
|
|
|
|
is => 'ro', |
|
91
|
|
|
|
|
|
|
lazy => 1, |
|
92
|
|
|
|
|
|
|
builder => 'pages', |
|
93
|
|
|
|
|
|
|
); |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
|
|
0
|
0
|
|
sub pages {{}} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
has statics_coderefs => ( |
|
99
|
|
|
|
|
|
|
is => 'ro', |
|
100
|
|
|
|
|
|
|
lazy => 1, |
|
101
|
|
|
|
|
|
|
builder => 'statics', |
|
102
|
|
|
|
|
|
|
); |
|
103
|
|
|
|
|
|
|
|
|
104
|
0
|
|
|
0
|
0
|
|
sub statics {{}} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
has web_path => ( |
|
108
|
|
|
|
|
|
|
is => 'ro', |
|
109
|
|
|
|
|
|
|
lazy => 1, |
|
110
|
|
|
|
|
|
|
builder => 1, |
|
111
|
|
|
|
|
|
|
); |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
0
|
|
0
|
|
|
sub _build_web_path { my @path = shift->path; defined $path[1] ? $path[1] : $path[0] } |
|
|
0
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
has template_path => ( |
|
117
|
|
|
|
|
|
|
is => 'ro', |
|
118
|
|
|
|
|
|
|
lazy => 1, |
|
119
|
|
|
|
|
|
|
builder => 1, |
|
120
|
|
|
|
|
|
|
); |
|
121
|
|
|
|
|
|
|
|
|
122
|
0
|
|
|
0
|
|
|
sub _build_template_path { my @path = shift->path; $path[0] } |
|
|
0
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=pod |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 NAME |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
DDG::Publisher::DirRole - The role for a directory in the publisher system |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 VERSION |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
version 1042 |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 key |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
The key inside the site for this directory. Required for instantiation. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 site |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Site object for this directory. Required for instantiation. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 files |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Contains a hash of the files for this directory. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 fullpath |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
This hash also contains all files, but with the full path on the filesystem |
|
155
|
|
|
|
|
|
|
as key, so that collides can be detected. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 pages_coderefs |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
This attribute contains all the coderefs for the pages that have to be |
|
160
|
|
|
|
|
|
|
generated for this specific directory. It uses L<pages> as builder. Normally |
|
161
|
|
|
|
|
|
|
you override L<pages> in your site class. |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 statics_coderefs |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This attribute contains all the coderefs for the static pages that have to be |
|
166
|
|
|
|
|
|
|
generated for this specific directory. It uses L<statics> as builder. Normally |
|
167
|
|
|
|
|
|
|
you override L<statics> in your site class. A static file is not generated for |
|
168
|
|
|
|
|
|
|
every language |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 web_path |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
The path on the web for this directory. |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 template_path |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This is the path inside the templates, used for the pages and statics of this |
|
177
|
|
|
|
|
|
|
directory. |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 AUTHOR |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Torsten Raudssus <torsten@raudss.us> |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
This software is Copyright (c) 2012 by DuckDuckGo, Inc. L<http://duckduckgo.com/>. |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
This is free software, licensed under: |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
The Apache License, Version 2.0, January 2004 |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |