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