line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::SiteTear::Page; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
|
|
|
|
|
|
#use Cwd; |
6
|
1
|
|
|
1
|
|
4
|
use File::Spec; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
7
|
1
|
|
|
1
|
|
5
|
use File::Basename; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
8
|
1
|
|
|
1
|
|
1009
|
use IO::File; |
|
1
|
|
|
|
|
12433
|
|
|
1
|
|
|
|
|
169
|
|
9
|
1
|
|
|
1
|
|
10
|
use File::Path; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
54
|
|
10
|
|
|
|
|
|
|
#use Data::Dumper; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
723
|
use HTML::SiteTear::PageFilter; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
11
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
require HTML::SiteTear::Item; |
15
|
|
|
|
|
|
|
our @ISA = qw(HTML::SiteTear::Item); |
16
|
|
|
|
|
|
|
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. 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
|
|
|
0
|
1
|
|
my $class = shift @_; |
51
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(@_); |
52
|
0
|
0
|
|
|
|
|
unless ($self->kind ) { $self->kind('page') }; |
|
0
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$self ->{'linkedFiles'} = []; |
54
|
0
|
|
|
|
|
|
return $self; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
our $_filter_module; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub page_filter { |
60
|
0
|
|
|
0
|
0
|
|
my ($class, $module) = @_; |
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
|
|
|
0
|
1
|
|
my ($self) = @_; |
76
|
0
|
|
|
|
|
|
my $parentFile = $self->parent->target_path; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $filter; |
79
|
0
|
0
|
|
|
|
|
if (defined $_filter_module) { |
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
|
0
|
|
|
|
|
unless (-e $source_path) { |
88
|
0
|
|
|
|
|
|
die("The file \"$source_path\" does not exists.\n"); |
89
|
0
|
|
|
|
|
|
return 0; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
unless ($self->exists_in_copied_files($source_path)){ |
93
|
0
|
|
|
|
|
|
my $target_path; |
94
|
0
|
0
|
|
|
|
|
if (my $target_uri = $self->item_in_filemap($source_path)) { |
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
|
0
|
|
|
|
|
my $io = IO::File->new("> $target_path") |
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
|
0
|
|
|
|
|
($source_path eq $target_path) and die "source and target is same file.\n"; |
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
|
|
|
0
|
0
|
|
my ($self, $io_layer) = @_; |
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
|
|
|
0
|
1
|
|
my ($self, $data) = @_; |
132
|
0
|
|
|
|
|
|
$self->{'OUT'}->print($data); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub build_abs_url { |
136
|
0
|
|
|
0
|
0
|
|
my ($self, $linkpath) = @_; |
137
|
0
|
|
|
|
|
|
my $link_uri = URI->new($linkpath); |
138
|
0
|
0
|
|
|
|
|
if ($link_uri->scheme) { |
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, L, L, L, L |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 AUTHOR |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Tetsuro KURITA |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; |