SiteTear/Page.pm

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