line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Contenticious::Generator; |
2
|
3
|
|
|
3
|
|
537028
|
use Mojo::Base -base; |
|
3
|
|
|
|
|
305081
|
|
|
3
|
|
|
|
|
19
|
|
3
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
511
|
use File::Basename; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
188
|
|
5
|
3
|
|
|
3
|
|
872
|
use File::Spec::Functions; # catdir, catfiles |
|
3
|
|
|
|
|
1312
|
|
|
3
|
|
|
|
|
202
|
|
6
|
3
|
|
|
3
|
|
938
|
use File::Share 'dist_dir'; |
|
3
|
|
|
|
|
58679
|
|
|
3
|
|
|
|
|
171
|
|
7
|
3
|
|
|
3
|
|
21
|
use FindBin; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
90
|
|
8
|
3
|
|
|
3
|
|
15
|
use File::Path 'make_path'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
117
|
|
9
|
3
|
|
|
3
|
|
792
|
use File::Copy; |
|
3
|
|
|
|
|
3798
|
|
|
3
|
|
|
|
|
1169
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has share_directory => dist_dir 'Contenticious'; |
12
|
|
|
|
|
|
|
has working_directory => $FindBin::Bin; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has files => sub{[ |
15
|
|
|
|
|
|
|
catfile(qw(config)), |
16
|
|
|
|
|
|
|
catfile(qw(webapp.pl)), |
17
|
|
|
|
|
|
|
catfile(qw(public styles.css)), |
18
|
|
|
|
|
|
|
catfile(qw(pages index.md)), |
19
|
|
|
|
|
|
|
catfile(qw(pages 01_Perldoc.md)), |
20
|
|
|
|
|
|
|
catfile(qw(pages 02_About.md)), |
21
|
|
|
|
|
|
|
]}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has is_executable => sub {{ |
24
|
|
|
|
|
|
|
catfile(qw(webapp.pl)) => 1, |
25
|
|
|
|
|
|
|
}}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _file_location { |
28
|
9
|
|
|
9
|
|
17
|
my ($self, $filename) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# check |
31
|
9
|
50
|
|
|
|
11
|
return unless grep {$_ eq $filename} @{$self->files}; |
|
54
|
|
|
|
|
120
|
|
|
9
|
|
|
|
|
24
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# concatenate |
34
|
9
|
|
|
|
|
23
|
return catfile $self->share_directory, $filename; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# store everything in files |
38
|
|
|
|
|
|
|
sub generate { |
39
|
1
|
|
|
1
|
1
|
1695
|
my $self = shift; |
40
|
1
|
|
|
|
|
2
|
$self->generate_file($_) for @{$self->files}; |
|
1
|
|
|
|
|
4
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# store a an asset in a file |
44
|
|
|
|
|
|
|
sub generate_file { |
45
|
9
|
|
|
9
|
1
|
2235
|
my ($self, $filename) = @_; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# check requested file name |
48
|
9
|
|
|
|
|
24
|
my $source = $self->_file_location($filename); |
49
|
9
|
50
|
|
|
|
92
|
die "Unknown file: '$filename'!\n" unless defined $source; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# determine path |
52
|
9
|
|
|
|
|
19
|
my $target = catfile $self->working_directory, $filename; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# create directory if neccessary |
55
|
9
|
|
|
|
|
343
|
my $target_dir = dirname $target; |
56
|
9
|
100
|
|
|
|
669
|
make_path $target_dir unless -d $target_dir; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# dump file |
59
|
9
|
|
|
|
|
49
|
copy $source => $target; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# chmod executable if neccessary |
62
|
9
|
50
|
|
|
|
2205
|
chmod oct(755) => $target if $self->is_executable($filename); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |