SiteTear/Root.pm

filter: Statementstmt 38.3% 23 / 60 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 37.5% 6 / 16 Podpod 60.0% 6 / 10 totaltotal 37.6% 35 / 93 CC 3 SCAR 12.0
CC
3
Cov
35%
new
12.0
set_default_folder_names
2.0
add_to_copyied_files
2.0
CRAP 3.3
« 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 File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 #use Cwd;
8 1 ▶use URI::file;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use base qw(Class::Accessor);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 HTML::SiteTear::Root->mk_accessors(qw(source_path
11 source_root_uri
12 resource_folder_name
13 page_folder_name
14 target_path
15 site_root_path
16 site_root_file_uri
17 site_root_uri
18 allow_abs_link
19 only_subitems));
20 #use Data::Dumper;
21  
22 1 our $VERSION = '1.43';
23  
24 =head1 NAME
25  
26 HTML::SiteTear::Root - a root object in a parent chain.
27  
28 =head1 SYMPOSIS
29  
30 use HTML::SiteTear::Root;
31  
32 $root = HTML::SiteTear::Root->new('source_path' => $source_path,
33 'target_path' => $destination_path);
34  
35 =head1 DESCRIPTION
36  
37 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.
38  
39 =cut
40  
41 1 our $defaultpage_folder_name = 'pages';
42 1 our $defaultresource_folder_name = 'assets';
43  
44 =head1 METHODS
45  
46 =head2 new
47  
48 $root = HTML::SiteTear::Root->new('source_path' => $source_path,
49 'target_path' => $destination_path);
50  
51 make a new instance.
52  
53 =cut
54  
55 sub new {
56 0 ▶ my $class = shift @_;
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
57 0 my %args = @_;
58 0 my $self = $class->SUPER::new(\%args);
59 0 $self->{'fileMapRef'} = {};
60 0 $self->{'copiedFiles'} = [];
61 0 $self->set_default_folder_names;
62
63 0 ▶ if ($self->site_root_path and $self->site_root_uri) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->site_root_path and $self->site_root_uri) 0 0 0
Condition0%0/3
$self->site_root_path and $self->site_root_uri
!ll&&!rl&&r
000
MC/DC0%0/2
$self->site_root_path and $self->site_root_uri
$self->site_root_path $self->site_root_uri
Truth table0%0/3
A and B
A= $self->site_root_pathB= $self->site_root_uri
ABresult
0X0
100
111
64 0 $self->allow_abs_link(1);
65 0 $self->site_root_file_uri(URI::file->new($self->site_root_path));
66 0 $self->site_root_uri(URI->new($self->site_root_uri));
67 }
68 0 $self->source_root_uri(URI::file->new($self->source_path));
69 0 return $self;
70 }
71  
72 sub set_default_folder_names {
73 0 ▶ my ($self) = @_;
Subroutine set_default_folder_names: not called CC=1 SCAR=6.9
Pod undocumented
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 sub add_to_copyied_files {
87 0 ▶ my ($self, $path) = @_;
Subroutine add_to_copyied_files: not called CC=1 SCAR=6.9
Pod documented
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 sub exists_in_copied_files {
102 0 ▶ my ($self, $path) = @_;
Subroutine exists_in_copied_files: not called CC=1 SCAR=6.9
Pod documented
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 sub add_to_filemap {
116 0 ▶ my ($self, $source_path, $destination_uri) = @_;
Subroutine add_to_filemap: not called CC=1 SCAR=6.9
Pod documented
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 sub exists_in_filemap {
131 0 ▶ my ($self, $path) = @_;
Subroutine exists_in_filemap: not called CC=1 SCAR=6.9
Pod documented
132 0 return exists($self->{fileMapRef}->{$path});
133 }
134  
135 sub item_in_filemap {
136 0 ▶ my ($self, $path) = @_;
Subroutine item_in_filemap: not called CC=1 SCAR=6.9
Pod undocumented
137 0 return $self->{'fileMapRef'}->{$path};
138 }
139  
140 =head2 rel_for_mappedfile
141  
142 $root->rel_for_mappedfile($source_path, $base_uri);
143  
144 get relative URI of copied file of $source_path from $base_uri.
145  
146 =cut
147  
148 sub rel_for_mappedfile {
149 0 ▶ my ($self, $source_path, $base_uri) = @_;
Subroutine rel_for_mappedfile: not called CC=1 SCAR=6.9
Pod documented
150 0 my $target_uri = $self->{'fileMapRef'}->{$source_path};
151 0 return $target_uri->rel($base_uri);
152 }
153  
154 sub source_root_path {
155 0 ▶ my $self = shift @_;
Subroutine source_root_path: not called CC=1 SCAR=6.9
Pod undocumented
156 0 return $self->source_path;
157 }
158  
159 sub source_root {
160 0 ▶ my $self = shift @_;
Subroutine source_root: not called CC=1 SCAR=6.9
Pod undocumented
161 0 return $self
162 }
163  
164 =head1 SEE ALSO
165  
166 L<HTML::SiteTear>, L<HTML::SiteTear::Page>, L<HTML::SiteTear::CSS>, L<HTML::SiteTear::Root>
167  
168 =head1 AUTHOR
169  
170 Tetsuro KURITA <tkurita@mac.com>
171  
172 =cut
173  
174 1 1;
« SiteTear/CSS.pm ↑ Summary