line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2014-2016 - Giovanni Simoni |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This file is part of PFT. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# PFT is free software: you can redistribute it and/or modify it under the |
6
|
|
|
|
|
|
|
# terms of the GNU General Public License as published by the Free |
7
|
|
|
|
|
|
|
# Software Foundation, either version 3 of the License, or (at your |
8
|
|
|
|
|
|
|
# option) any later version. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# PFT is distributed in the hope that it will be useful, but WITHOUT ANY |
11
|
|
|
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12
|
|
|
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
13
|
|
|
|
|
|
|
# for more details. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License along |
16
|
|
|
|
|
|
|
# with PFT. If not, see . |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
package PFT::Tree v1.3.0; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=encoding utf8 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
PFT::Tree - Filesystem tree mapping a PFT site |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
PFT::Tree->new(); |
29
|
|
|
|
|
|
|
PFT::Tree->new($basedir); |
30
|
|
|
|
|
|
|
PFT::Tree->new($basedir, {create => 1}); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
The structure is the following: |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
├── build |
37
|
|
|
|
|
|
|
├── content |
38
|
|
|
|
|
|
|
│ └── ... |
39
|
|
|
|
|
|
|
├── inject |
40
|
|
|
|
|
|
|
├── pft.yaml |
41
|
|
|
|
|
|
|
└── templates |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Where: |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=over |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item C is a directory is handled with a C |
48
|
|
|
|
|
|
|
instance. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item C is a configuration file handled with C |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item The remaining directories are just created, but the content is not |
53
|
|
|
|
|
|
|
handled by the C structure. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
2
|
|
163068
|
use utf8; |
|
2
|
|
|
|
|
25
|
|
|
2
|
|
|
|
|
14
|
|
58
|
2
|
|
|
2
|
|
72
|
use v5.16; |
|
2
|
|
|
|
|
7
|
|
59
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
41
|
|
60
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
70
|
|
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
2
|
|
23
|
use File::Spec; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
50
|
|
63
|
2
|
|
|
2
|
|
10
|
use File::Path qw/make_path/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
135
|
|
64
|
2
|
|
|
2
|
|
12
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
127
|
|
65
|
2
|
|
|
2
|
|
19
|
use Cwd; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
117
|
|
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
2
|
|
1250
|
use PFT::Content; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
60
|
|
68
|
2
|
|
|
2
|
|
846
|
use PFT::Conf; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
95
|
|
69
|
2
|
|
|
2
|
|
888
|
use PFT::Map; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
963
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub new { |
72
|
5
|
|
|
5
|
0
|
2400
|
my($cls, $given, $opts) = @_; |
73
|
|
|
|
|
|
|
|
74
|
5
|
100
|
|
|
|
66
|
if ($opts->{create}) { |
|
|
100
|
|
|
|
|
|
75
|
3
|
50
|
|
|
|
20
|
defined $given or confess "Base dir is mandatory if creating"; |
76
|
3
|
|
|
|
|
14
|
my $root = PFT::Conf::locate($given); |
77
|
3
|
100
|
66
|
|
|
17
|
if (defined $root and $root ne $given) { |
78
|
1
|
|
|
|
|
171
|
confess "Cannot nest. Found a root in $root"; |
79
|
|
|
|
|
|
|
} |
80
|
2
|
|
|
|
|
9
|
my $self = bless { root => $given }, $cls; |
81
|
2
|
|
|
|
|
10
|
$self->_create(); |
82
|
2
|
|
|
|
|
11
|
$self |
83
|
|
|
|
|
|
|
} elsif (defined(my $root = PFT::Conf::locate($given))) { |
84
|
1
|
|
|
|
|
10
|
bless { root => $root }, $cls; |
85
|
|
|
|
|
|
|
} else { |
86
|
1
|
|
33
|
|
|
199
|
croak 'Cannot find tree in ', $given || Cwd::cwd; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _create { |
91
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
92
|
2
|
|
|
|
|
7
|
make_path map({ $self->$_ } qw/ |
|
6
|
|
|
|
|
41
|
|
93
|
|
|
|
|
|
|
dir_content |
94
|
|
|
|
|
|
|
dir_templates |
95
|
|
|
|
|
|
|
dir_inject |
96
|
|
|
|
|
|
|
/), { |
97
|
|
|
|
|
|
|
#verbose => 1, |
98
|
|
|
|
|
|
|
mode => 0711, |
99
|
|
|
|
|
|
|
}; |
100
|
|
|
|
|
|
|
|
101
|
2
|
50
|
|
|
|
394
|
unless (PFT::Conf::isroot(my $root = $self->{root})) { |
102
|
2
|
|
|
|
|
17
|
PFT::Conf->new_default->save_to($root); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
2
|
|
|
|
|
25
|
$self->content(create => 1); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 Properties |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=over 1 |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item dir_content |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
5
|
|
|
5
|
1
|
50
|
sub dir_content { File::Spec->catdir(shift->{root}, 'content') } |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
0
|
0
|
0
|
sub dir_base { shift->{root} } |
119
|
2
|
|
|
2
|
0
|
11
|
sub dir_templates { File::Spec->catdir(shift->{root}, 'templates') } |
120
|
2
|
|
|
2
|
0
|
367
|
sub dir_inject { File::Spec->catdir(shift->{root}, 'inject') } |
121
|
0
|
|
|
0
|
0
|
0
|
sub dir_build { File::Spec->catdir(shift->{root}, 'build') } |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item content |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Returns a C object, abstracting the access to the I |
126
|
|
|
|
|
|
|
directory. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
3
|
|
|
3
|
1
|
12
|
sub content { PFT::Content->new(shift->dir_content, {@_}) } |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item map |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Returns a C object, abstracting the the content graph. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
0
|
0
|
|
sub content_map { PFT::Map->new(shift->content) } |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item conf |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Returns a C object, abstracting the configuration file. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
0
|
1
|
|
sub conf { PFT::Conf->new_load(shift->{root}) } |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=back |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |