SiteTear/Page.pm

filter: Statementstmt 33.3% 26 / 78 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 53.8% 7 / 13 Podpod 50.0% 3 / 6 totaltotal 31.8% 36 / 113 CC 9 SCAR 30.2
CC
9
Cov
28%
copy_to_linkpath
56.0
new
6.0
build_abs_url
6.0
CRAP 20.4
« SiteTear.pm ↑ Summary SiteTear/CSS.pm »
1 package HTML::SiteTear::Page;
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 #use Cwd;
6 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 #use Data::Dumper;
11  
12 1 ▶use HTML::SiteTear::PageFilter;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 require HTML::SiteTear::Item;
15 1 our @ISA = qw(HTML::SiteTear::Item);
16 1 our $VERSION = '1.43';
17  
18 =head1 NAME
19  
20 HTML::SiteTear::Page - treat HTML files
21  
22 =head1 SYMPOSIS
23  
24 use HTML::SiteTear::Page;
25  
26 $page = HTML::SiteTear::Page->new($parent, $source_path, $kind);
27 $page->linkpath($path); # usually called from the mothod "change_path"
28 # of the parent object.
29 $page->copy_to_linkpath();
30 $page->copy_linked_files();
31  
32 =head1 DESCRIPTION
33  
34 This module is to tread HTML files. It's also a sub class of L<HTML::SiteTear::Item>. Internal use only.
35  
36 =head1 METHODS
37  
38 =head2 new
39  
40 $page = HTML::SiteTear::Page->new('parent' => $parent,
41 'source_path' => $source_path);
42  
43 Make an instance of HTML::SiteTear::Page class.
44  
45 $parent is an instance of HTML::SiteTear::Page which have an link to $source_path. $source_path is a path to a HTML file. $kind must be 'page'.
46  
47 =cut
48  
49 sub new {
50 0 ▶ my $class = shift @_;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
51 0 my $self = $class->SUPER::new(@_);
52 0 ▶ unless ($self->kind ) { $self->kind('page') };
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->kind) 0 0 0
53 0 $self ->{'linkedFiles'} = [];
54 0 return $self;
55 }
56  
57 1 our $_filter_module;
58  
59 sub page_filter {
60 0 ▶ my ($class, $module) = @_;
Subroutine page_filter: not called CC=1 SCAR=6.9
Pod undocumented
61 0 $_filter_module = $module;
62 0 return eval "require $_filter_module";
63 }
64  
65 =head2 copy_to_linkpath
66  
67 $page->copy_to_linkpath;
68  
69 Copy $source_path into new linked path from $parent.
70  
71 =cut
72  
73 sub copy_to_linkpath {
74 #print "start copy_to_linkpath\n";
75 0 ▶ my ($self) = @_;
Subroutine copy_to_linkpath: not called CC=7 SCAR=40.3
Pod documented
76 0 my $parentFile = $self->parent->target_path;
77  
78 0 my $filter;
79 0 ▶ if (defined $_filter_module) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $HTML::SiteTear::Page::_filter_module) { } 0 0 0
80 0 $filter = $_filter_module->new($self);
81 }
82 else {
83 0 $filter = HTML::SiteTear::PageFilter->new($self);
84 }
85
86 0 my $source_path = $self->source_path;
87 0 ▶ unless (-e $source_path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $source_path) 0 0 0
88 0 die("The file \"$source_path\" does not exists.\n");
89 0 return 0;
90 }
91  
92 0 ▶ unless ($self->exists_in_copied_files($source_path)){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->exists_in_copied_files($source_path)) 0 0 0
93 0 my $target_path;
94 0 ▶ if (my $target_uri = $self->item_in_filemap($source_path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $target_uri = $self->item_in_filemap($source_path)) { } 0 0 0
95 0 $target_path = $target_uri->file;
96 } else {
97 0 $target_path = $self->link_uri->file;
98 }
99
100 0 mkpath(dirname($target_path));
101 0 ▶ my $io = IO::File->new("> $target_path")
Branch: 1 branch
BranchTrueFalseTotal
my $io = "IO::File"->new("> $target_path") or die "Can't open $target_path" 0 0 0
102 or die "Can't open $target_path";
103 #$target_path = Cwd::realpath($target_path);
104 0 $self->target_path($target_path);
105 0 $self->{'OUT'} = $io;
106 0 print "\nCopying HTML...\n";
107 0 print "from : $source_path\n";
108 0 print "to : $target_path\n";
109 0 ▶ ($source_path eq $target_path) and die "source and target is same file.\n";
Branch: 1 branch
BranchTrueFalseTotal
$source_path eq $target_path and die "source and target is same file.\n" 0 0 0
110 0 $filter->parse_file;
111 0 $io->close;
112 0 $self->add_to_copyied_files($source_path);
113 0 $self->copy_linked_files;
114 }
115 }
116  
117 sub set_binmode {
118 0 ▶ my ($self, $io_layer) = @_;
Subroutine set_binmode: not called CC=1 SCAR=6.9
Pod undocumented
119 0 binmode($self->{'OUT'}, $io_layer);
120 }
121  
122 =head2 write_data
123  
124 $page->write_data($data)
125  
126 Write HTML data to the linked path form the parent object. This method is called from HTML::SiteTear::PageFilder.
127  
128 =cut
129  
130 sub write_data {
131 0 ▶ my ($self, $data) = @_;
Subroutine write_data: not called CC=1 SCAR=6.9
Pod documented
132 0 $self->{'OUT'}->print($data);
133 }
134  
135 sub build_abs_url {
136 0 ▶ my ($self, $linkpath) = @_;
Subroutine build_abs_url: not called CC=2 SCAR=17.9
Pod undocumented
137 0 my $link_uri = URI->new($linkpath);
138 0 ▶ if ($link_uri->scheme) {
Branch: 1 branch
BranchTrueFalseTotal
if ($link_uri->scheme) 0 0 0
139 0 return $linkpath;
140 }
141 0 my $abs_uri = $link_uri->abs($self->source_uri);
142 0 my $rel_from_root = $abs_uri->rel($self->source_root->site_root_file_uri);
143 0 my $abs_in_site = $rel_from_root->abs($self->source_root->site_root_uri);
144 0 print "\nConverting to absolute link...\n";
145 0 print "from a link ".$link_uri."\n";
146 0 print "in ".$self->source_path."\n";
147 0 print "into ".$abs_in_site->as_string."\n";
148 0 return $abs_in_site->as_string;
149 }
150  
151 =head1 SEE ALOSO
152  
153 L<HTML::SiteTear>, L<HTML::SiteTear::Item>, L<HTML::SiteTear::CSS>, L<HTML::SiteTear::Root>, L<HTML::SiteTear::dPageFilter>
154  
155 =head1 AUTHOR
156  
157 Tetsuro KURITA <tkurita@mac.com>
158  
159 =cut
160  
161 1 1;
« SiteTear.pm ↑ Summary SiteTear/CSS.pm »