SiteTear/Root.pm

filter: Statementstmt 25.7% 17 / 66 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 25.0% 4 / 16 Podpod 50.0% 6 / 12 totaltotal 25.2% 27 / 107 CC 6 SCAR 19.0
CC
6
Cov
22%
site_root_path
20.0
new
12.0
set_default_folder_names
2.0
CRAP 6.7
« SiteTear/CSS.pm ↑ Summary
1 package HTML::SiteTear::Root;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use URI::file;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 #use Data::Dumper;
7  
8 1 ▶use base qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 __PACKAGE__->mk_accessors(qw(source_path
10 source_root_uri
11 resource_folder_name
12 page_folder_name
13 target_path
14 site_root_local_uri
15 site_root_uri
16 allow_abs_link
17 only_subitems));
18  
19 1 our $VERSION = '1.45';
20  
21 =head1 NAME
22  
23 HTML::SiteTear::Root - a root object in a parent chain.
24  
25 =head1 SYMPOSIS
26  
27 use HTML::SiteTear::Root;
28  
29 $root = HTML::SiteTear::Root->new('source_path' => $source_path,
30 'target_path' => $destination_path);
31  
32 =head1 DESCRIPTION
33  
34 An instanece of this module is for a root object in a parent chain and manage a relation tabel of all source pathes and target pathes. Also gives default folder names.
35  
36 =cut
37  
38 1 our $defaultpage_folder_name = 'pages';
39 1 our $defaultresource_folder_name = 'assets';
40  
41 =head1 METHODS
42  
43 =head2 new
44  
45 $root = HTML::SiteTear::Root->new('source_path' => $source_path,
46 'target_path' => $destination_path);
47  
48 make a new instance.
49  
50 =cut
51  
52 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
53 0 my $class = shift @_;
54 0 my %args = @_;
55 0 my $self = $class->SUPER::new(\%args);
56 0 $self->{'fileMapRef'} = {};
57 0 $self->{'copiedFiles'} = [];
58 0 $self->set_default_folder_names;
59
60 0 ▶ if ($self->site_root_path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->site_root_path) 0 0 0
61 0 $self->site_root_path($self->site_root_path);
62 0 ▶ if ($self->site_root_uri) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->site_root_uri) 0 0 0
63 0 $self->allow_abs_link(1);
64 0 $self->site_root_local_uri(URI::file->new($self->site_root_path));
65 0 $self->site_root_uri(URI->new($self->site_root_uri));
66 }
67 }
68 0 $self->source_root_uri(URI::file->new($self->source_path));
69 0 return $self;
70 }
71  
72 0 ▶sub set_default_folder_names {
Subroutine set_default_folder_names: not called CC=1 SCAR=6.9
Pod undocumented
73 0 my ($self) = @_;
74 0 $self->resource_folder_name($defaultresource_folder_name);
75 0 $self->page_folder_name($defaultpage_folder_name);
76 }
77  
78 =head2 add_to_copyied_files
79  
80 $item->add_to_copyied_files($source_path)
81  
82 Add a file path already copied to the copiedFiles table of the root object of the parent chain.
83  
84 =cut
85  
86 0 ▶sub add_to_copyied_files {
Subroutine add_to_copyied_files: not called CC=1 SCAR=6.9
Pod documented
87 0 my ($self, $path) = @_;
88 #$path = Cwd::realpath($path);
89 0 push @{$self->{'copiedFiles'}}, $path;
90 0 return $path;
91 }
92  
93 =head2 exists_in_copied_files
94  
95 $item->exists_in_copied_files($source_path)
96  
97 Check existance of $source_path in the copiedFiles entry.
98  
99 =cut
100  
101 0 ▶sub exists_in_copied_files {
Subroutine exists_in_copied_files: not called CC=1 SCAR=6.9
Pod documented
102 0 my ($self, $path) = @_;
103 0 return grep(/^$path$/, @{$self->{'copiedFiles'}});
104 }
105  
106 =head2 add_to_filemap
107  
108 $root->add_to_filemap($source_path, $destination_uri);
109  
110 Add to copyied file information into the internal table "filemap".
111 A fragment of $destination_uri is dropped.
112  
113 =cut
114  
115 0 ▶sub add_to_filemap {
Subroutine add_to_filemap: not called CC=1 SCAR=6.9
Pod documented
116 0 my ($self, $source_path, $destination_uri) = @_;
117 0 $destination_uri->fragment(undef);
118 0 $self->{'fileMapRef'}->{$source_path} = $destination_uri;
119 0 return $destination_uri;
120 }
121  
122 =head2 exists_in_filemap
123  
124 $root->exists_in_filemap($source_path);
125  
126 check $source_path is entry in FileMap
127  
128 =cut
129  
130 0 ▶sub exists_in_filemap {
Subroutine exists_in_filemap: not called CC=1 SCAR=6.9
Pod documented
131 0 my ($self, $path) = @_;
132 0 return exists($self->{fileMapRef}->{$path});
133 }
134  
135 0 ▶sub item_in_filemap {
Subroutine item_in_filemap: not called CC=1 SCAR=6.9
Pod undocumented
136 0 my ($self, $path) = @_;
137 0 return $self->{'fileMapRef'}->{$path};
138 }
139  
140 0 ▶sub exists_in_target_files {
Subroutine exists_in_target_files: not called CC=1 SCAR=6.9
Pod undocumented
141 0 my ($self, $path) = @_;
142 0 return grep(/^$path$/, values %{$self->{fileMapRef}});
143 }
144  
145 =head2 rel_for_mappedfile
146  
147 $root->rel_for_mappedfile($source_path, $base_uri);
148  
149 get relative URI of copied file of $source_path from $base_uri.
150  
151 =cut
152  
153 0 ▶sub rel_for_mappedfile {
Subroutine rel_for_mappedfile: not called CC=1 SCAR=6.9
Pod documented
154 0 my ($self, $source_path, $base_uri) = @_;
155 0 my $target_uri = $self->{'fileMapRef'}->{$source_path};
156 0 return $target_uri->rel($base_uri);
157 }
158  
159 0 ▶sub source_root_path {
Subroutine source_root_path: not called CC=1 SCAR=6.9
Pod undocumented
160 0 my $self = shift @_;
161 0 return $self->source_path;
162 }
163  
164 0 ▶sub source_root {
Subroutine source_root: not called CC=1 SCAR=6.9
Pod undocumented
165 0 my $self = shift @_;
166 0 return $self
167 }
168  
169 0 ▶sub site_root_path {
Subroutine site_root_path: not called CC=4 SCAR=30.0
Pod undocumented
170 0 my $self = shift @_;
171 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
172 0 my $path = $_[0];
173 0 ▶ if (-d $path and $path !~ /\/$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $path and not $path =~ m[/$]) 0 0 0
Condition0%0/3
-d $path and not $path =~ m[/$]
!ll&&!rl&&r
000
MC/DC0%0/2
-d $path and not $path =~ m[/$]
-d $path not $path =~ m[/$]
Truth table0%0/3
A and not(B)
A= -d $pathB= not $path =~ m[/$]
ABresult
0X0
100
111
174 0 $path = $path.'/';
175 }
176 0 $self->{'site_root_path'} = $path;
177 }
178 0 return $self->{'site_root_path'};
179 }
180  
181 =head1 SEE ALSO
182  
183 L<HTML::SiteTear>, L<HTML::SiteTear::Page>, L<HTML::SiteTear::CSS>, L<HTML::SiteTear::Root>
184  
185 =head1 AUTHOR
186  
187 Tetsuro KURITA <tkurita@mac.com>
188  
189 =cut
190  
191 1 1;
« SiteTear/CSS.pm ↑ Summary