| 1 | package App::Followme::WebData; | ||||||||||||
| 2 | |||||||||||||
| 3 | 12 | ▶ | use 5.008005; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 12 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 12 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 12 | ▶ | use integer; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 12 | ▶ | use lib '../..'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 12 | ▶ | use base qw(App::Followme::FileData); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 12 | ▶ | use App::Followme::FIO; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 12 | ▶ | use App::Followme::Web; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | 12 | our $VERSION = "2.03"; | |||||||||||
| 14 | |||||||||||||
| 15 | #---------------------------------------------------------------------- | ||||||||||||
| 16 | # Read the default parameter values | ||||||||||||
| 17 | |||||||||||||
| 18 | 288 | ▶ | sub parameters { | ||||||||||
|
Subroutine
parameters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 19 | 288 | my ($self) = @_; | |||||||||||
| 20 | |||||||||||||
| 21 | return ( | ||||||||||||
| 22 | 288 | body_tag => 'primary', | |||||||||||
| 23 | metadata_tag => 'meta', | ||||||||||||
| 24 | ); | ||||||||||||
| 25 | } | ||||||||||||
| 26 | |||||||||||||
| 27 | #---------------------------------------------------------------------- | ||||||||||||
| 28 | # Get the html metadata from the page header | ||||||||||||
| 29 | |||||||||||||
| 30 | 54 | ▶ | sub fetch_metadata { | ||||||||||
|
Subroutine
fetch_metadata: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 31 | 54 | my ($self, $metadata_block) = @_; | |||||||||||
| 32 | 54 | my $metadata = []; | |||||||||||
| 33 | |||||||||||||
| 34 | 54 | my $global = 0; | |||||||||||
| 35 | 54 | ▶ | my $title_parser = sub { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 36 | 54 | my ($metadata, @tokens) = @_; | |||||||||||
| 37 | 54 | my $text = web_only_text(@tokens); | |||||||||||
| 38 | 54 | push(@$metadata, 'title', $text); | |||||||||||
| 39 | 54 | return; | |||||||||||
| 40 | 54 | }; | |||||||||||
| 41 | |||||||||||||
| 42 | 54 | web_match_tags('<title></title>', $metadata_block, | |||||||||||
| 43 | $title_parser, $metadata, $global); | ||||||||||||
| 44 | |||||||||||||
| 45 | 54 | $global = 1; | |||||||||||
| 46 | 167 | ▶ | my $metadata_parser = sub { | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||
| 47 | 167 | my ($metadata, @tokens) = @_; | |||||||||||
| 48 | 167 | foreach my $tag (web_only_tags(@tokens)) { | |||||||||||
| 49 | 167 | push(@$metadata, $tag->{name}, $tag->{content}); | |||||||||||
| 50 | } | ||||||||||||
| 51 | 167 | return; | |||||||||||
| 52 | 54 | }; | |||||||||||
| 53 | |||||||||||||
| 54 | 54 | web_match_tags('<meta name=* content=*>', $metadata_block, | |||||||||||
| 55 | $metadata_parser, $metadata, $global); | ||||||||||||
| 56 | |||||||||||||
| 57 | 54 | my %metadata = @$metadata; | |||||||||||
| 58 | 54 | return %metadata; | |||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | #---------------------------------------------------------------------- | ||||||||||||
| 62 | # Split text into metadata and content sections | ||||||||||||
| 63 | |||||||||||||
| 64 | 54 | ▶ | sub fetch_sections { | ||||||||||
|
Subroutine
fetch_sections: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 65 | 54 | my ($self, $text) = @_; | |||||||||||
| 66 | |||||||||||||
| 67 | 54 | my $section = web_parse_sections($text); | |||||||||||
| 68 | |||||||||||||
| 69 | 54 | my %section; | |||||||||||
| 70 | 54 | foreach my $section_name (qw(metadata body)) { | |||||||||||
| 71 | 108 | my $tag = $self->{$section_name . '_tag'}; | |||||||||||
| 72 | 108 | ▶ | $section{$section_name} = $section->{$tag} || ''; | ||||||||||
|
Condition100%2/2
$section->{$tag} || ''
MC/DC100%1/1
$section->{$tag} || ''
$section->{$tag}
Truth table100%2/2
A
A= $section->{$tag}
| |||||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | 54 | return \%section; | |||||||||||
| 76 | } | ||||||||||||
| 77 | |||||||||||||
| 78 | 12 | 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 | ||||||||||||