line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Followme::WebData; |
2
|
|
|
|
|
|
|
|
3
|
12
|
|
|
12
|
|
793
|
use 5.008005; |
|
12
|
|
|
|
|
61
|
|
4
|
12
|
|
|
12
|
|
81
|
use strict; |
|
12
|
|
|
|
|
53
|
|
|
12
|
|
|
|
|
348
|
|
5
|
12
|
|
|
12
|
|
70
|
use warnings; |
|
12
|
|
|
|
|
32
|
|
|
12
|
|
|
|
|
393
|
|
6
|
12
|
|
|
12
|
|
71
|
use integer; |
|
12
|
|
|
|
|
20
|
|
|
12
|
|
|
|
|
85
|
|
7
|
12
|
|
|
12
|
|
350
|
use lib '../..'; |
|
12
|
|
|
|
|
44
|
|
|
12
|
|
|
|
|
77
|
|
8
|
|
|
|
|
|
|
|
9
|
12
|
|
|
12
|
|
1691
|
use base qw(App::Followme::FileData); |
|
12
|
|
|
|
|
28
|
|
|
12
|
|
|
|
|
5005
|
|
10
|
12
|
|
|
12
|
|
87
|
use App::Followme::FIO; |
|
12
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
1055
|
|
11
|
12
|
|
|
12
|
|
82
|
use App::Followme::Web; |
|
12
|
|
|
|
|
52
|
|
|
12
|
|
|
|
|
4215
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = "2.03"; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
16
|
|
|
|
|
|
|
# Read the default parameter values |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub parameters { |
19
|
288
|
|
|
288
|
1
|
540
|
my ($self) = @_; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
return ( |
22
|
288
|
|
|
|
|
868
|
body_tag => 'primary', |
23
|
|
|
|
|
|
|
metadata_tag => 'meta', |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
28
|
|
|
|
|
|
|
# Get the html metadata from the page header |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub fetch_metadata { |
31
|
54
|
|
|
54
|
0
|
117
|
my ($self, $metadata_block) = @_; |
32
|
54
|
|
|
|
|
95
|
my $metadata = []; |
33
|
|
|
|
|
|
|
|
34
|
54
|
|
|
|
|
89
|
my $global = 0; |
35
|
|
|
|
|
|
|
my $title_parser = sub { |
36
|
54
|
|
|
54
|
|
154
|
my ($metadata, @tokens) = @_; |
37
|
54
|
|
|
|
|
136
|
my $text = web_only_text(@tokens); |
38
|
54
|
|
|
|
|
124
|
push(@$metadata, 'title', $text); |
39
|
54
|
|
|
|
|
116
|
return; |
40
|
54
|
|
|
|
|
251
|
}; |
41
|
|
|
|
|
|
|
|
42
|
54
|
|
|
|
|
182
|
web_match_tags('<title></title>', $metadata_block, |
43
|
|
|
|
|
|
|
$title_parser, $metadata, $global); |
44
|
|
|
|
|
|
|
|
45
|
54
|
|
|
|
|
95
|
$global = 1; |
46
|
|
|
|
|
|
|
my $metadata_parser = sub { |
47
|
167
|
|
|
167
|
|
345
|
my ($metadata, @tokens) = @_; |
48
|
167
|
|
|
|
|
348
|
foreach my $tag (web_only_tags(@tokens)) { |
49
|
167
|
|
|
|
|
552
|
push(@$metadata, $tag->{name}, $tag->{content}); |
50
|
|
|
|
|
|
|
} |
51
|
167
|
|
|
|
|
464
|
return; |
52
|
54
|
|
|
|
|
251
|
}; |
53
|
|
|
|
|
|
|
|
54
|
54
|
|
|
|
|
201
|
web_match_tags('<meta name=* content=*>', $metadata_block, |
55
|
|
|
|
|
|
|
$metadata_parser, $metadata, $global); |
56
|
|
|
|
|
|
|
|
57
|
54
|
|
|
|
|
240
|
my %metadata = @$metadata; |
58
|
54
|
|
|
|
|
631
|
return %metadata; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
62
|
|
|
|
|
|
|
# Split text into metadata and content sections |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub fetch_sections { |
65
|
54
|
|
|
54
|
0
|
151
|
my ($self, $text) = @_; |
66
|
|
|
|
|
|
|
|
67
|
54
|
|
|
|
|
198
|
my $section = web_parse_sections($text); |
68
|
|
|
|
|
|
|
|
69
|
54
|
|
|
|
|
102
|
my %section; |
70
|
54
|
|
|
|
|
107
|
foreach my $section_name (qw(metadata body)) { |
71
|
108
|
|
|
|
|
245
|
my $tag = $self->{$section_name . '_tag'}; |
72
|
108
|
|
100
|
|
|
698
|
$section{$section_name} = $section->{$tag} || ''; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
54
|
|
|
|
|
178
|
return \%section; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=pod |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=encoding utf-8 |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 NAME |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
App::Followme::WebData - Read metadata from a web file |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 SYNOPSIS |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
use App::Followme::WebData; |
91
|
|
|
|
|
|
|
my $data = App::Followme::WebData->new(); |
92
|
|
|
|
|
|
|
my $html = App::Followme::Template->new('example.htm', $data); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 DESCRIPTION |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This module extracts data from a web page and uses it to build variables from a |
97
|
|
|
|
|
|
|
template. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 METHODS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
All data classes are first instantiated by calling new and the object |
102
|
|
|
|
|
|
|
created is passed to a template object. It calls the build method with an |
103
|
|
|
|
|
|
|
argument name to retrieve that data item, though for the sake of |
104
|
|
|
|
|
|
|
efficiency, all the data are read from the file at once. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 VARIABLES |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This class whatever values are returned in metadata section in the header |
109
|
|
|
|
|
|
|
as well as the title and body extracted from the body section. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 CONFIGURATION |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This class has the following configuration variable: |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=over 4 |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item body_tag |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
The name of the section containing the body text. The default value is |
120
|
|
|
|
|
|
|
'primary'. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item metadata_tag |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
The name of the section containing the metadata tags. The default value is |
125
|
|
|
|
|
|
|
'meta'. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item extension |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
The file extension of web pages. The default value is 'html'. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 LICENSE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Copyright (C) Bernie Simon. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
138
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 AUTHOR |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Bernie Simon E<lt>bernie.simon@gmail.comE<gt> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |