| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package URL::Transform::using::HTML::Meta; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | =head1 NAME | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | URL::Transform::using::HTML::Meta - regular expression parsing of the meta content attribute for url transformation | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | my $urlt = URL::Transform::using::HTML::Meta->new( | 
| 10 |  |  |  |  |  |  | 'output_function'    => sub { $output .= "@_" }, | 
| 11 |  |  |  |  |  |  | 'transform_function' => sub { return (join '|', @_) }, | 
| 12 |  |  |  |  |  |  | ); | 
| 13 |  |  |  |  |  |  | $urlt->parse_string("0;url = 'some other link'"); | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | print "and this is the output: ", $output; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | Using module you can performs an url transformation on the HTML META | 
| 21 |  |  |  |  |  |  | content attribute string. | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | This module is used by L. | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | =cut | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 1 |  |  | 1 |  | 7 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 60 |  | 
| 28 | 1 |  |  | 1 |  | 5 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 76 |  | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | our $VERSION = '0.01'; | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 1 |  |  | 1 |  | 6 | use Carp::Clan; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 11 |  | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 1 |  |  | 1 |  | 226 | use base 'Class::Accessor::Fast'; | 
|  | 1 |  |  |  |  | 10 |  | 
|  | 1 |  |  |  |  | 462 |  | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | my $META_URL_REGEXP = qr{    # ex. "0;URL=http://some.server.com/" | 
| 38 |  |  |  |  |  |  | ^ (           # capture non url path of the string | 
| 39 |  |  |  |  |  |  | \s* | 
| 40 |  |  |  |  |  |  | [0-9]+    # number of seconds after which to refresh | 
| 41 |  |  |  |  |  |  | \s* | 
| 42 |  |  |  |  |  |  | ; | 
| 43 |  |  |  |  |  |  | \s* | 
| 44 |  |  |  |  |  |  | url\s*=      # url= (case insensitive) | 
| 45 |  |  |  |  |  |  | \s* | 
| 46 |  |  |  |  |  |  | ['"]? | 
| 47 |  |  |  |  |  |  | ) | 
| 48 |  |  |  |  |  |  | (             # the rest is url | 
| 49 |  |  |  |  |  |  | .+ | 
| 50 |  |  |  |  |  |  | ) | 
| 51 |  |  |  |  |  |  | ( | 
| 52 |  |  |  |  |  |  | ['"]? | 
| 53 |  |  |  |  |  |  | \s* | 
| 54 |  |  |  |  |  |  | ) | 
| 55 |  |  |  |  |  |  | $ | 
| 56 |  |  |  |  |  |  | }xmsi; | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =head1 PROPERTIES | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | output_function | 
| 62 |  |  |  |  |  |  | transform_function | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | =cut | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | __PACKAGE__->mk_accessors(qw{ | 
| 67 |  |  |  |  |  |  | output_function | 
| 68 |  |  |  |  |  |  | transform_function | 
| 69 |  |  |  |  |  |  | }); | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =head1 METHODS | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =cut | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | =head2 new | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | Object constructor. | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | Requires: | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | output_function | 
| 83 |  |  |  |  |  |  | transform_function | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | =cut | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | sub new { | 
| 88 | 3 |  |  | 3 | 1 | 42 | my $class = shift; | 
| 89 |  |  |  |  |  |  |  | 
| 90 | 3 |  |  |  |  | 21 | my $self = $class->SUPER::new({ @_ }); | 
| 91 |  |  |  |  |  |  |  | 
| 92 | 3 |  |  |  |  | 36 | my $output_function    = $self->output_function; | 
| 93 | 3 |  |  |  |  | 23 | my $transform_function = $self->transform_function; | 
| 94 |  |  |  |  |  |  |  | 
| 95 | 3 | 50 |  |  |  | 18 | croak 'pass print function' | 
| 96 |  |  |  |  |  |  | if not (ref $output_function eq 'CODE'); | 
| 97 |  |  |  |  |  |  |  | 
| 98 | 3 | 50 |  |  |  | 12 | croak 'pass transform url function' | 
| 99 |  |  |  |  |  |  | if not (ref $transform_function eq 'CODE'); | 
| 100 |  |  |  |  |  |  |  | 
| 101 | 3 |  |  |  |  | 9 | return $self; | 
| 102 |  |  |  |  |  |  | } | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | =head2 parse_string($string) | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | Submit meta content string for parsing. | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | =cut | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | sub parse_string { | 
| 112 | 3 |  |  | 3 | 1 | 4 | my $self   = shift; | 
| 113 | 3 |  |  |  |  | 6 | my $string = shift; | 
| 114 |  |  |  |  |  |  |  | 
| 115 | 3 | 100 |  |  |  | 24 | if ($string =~ $META_URL_REGEXP) { | 
| 116 | 2 |  |  |  |  | 4 | my $meta_content_start = $1; | 
| 117 | 2 |  |  |  |  | 4 | my $url                = $2; | 
| 118 | 2 |  |  |  |  | 5 | my $meta_content_end   = $3; | 
| 119 |  |  |  |  |  |  |  | 
| 120 | 2 |  |  |  |  | 6 | $url = $self->transform_function->( | 
| 121 |  |  |  |  |  |  | 'tag_name'       => 'meta', | 
| 122 |  |  |  |  |  |  | 'attribute_name' => 'content', | 
| 123 |  |  |  |  |  |  | 'url'            => $url, | 
| 124 |  |  |  |  |  |  | ); | 
| 125 |  |  |  |  |  |  |  | 
| 126 | 2 |  |  |  |  | 49 | $self->output_function->( | 
| 127 |  |  |  |  |  |  | $meta_content_start.$url.$meta_content_end | 
| 128 |  |  |  |  |  |  | ); | 
| 129 |  |  |  |  |  |  | } | 
| 130 |  |  |  |  |  |  | else { | 
| 131 | 1 |  |  |  |  | 3 | $self->output_function->($string); | 
| 132 |  |  |  |  |  |  | } | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | } | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | =head2 parse_file($file_name) | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | makes no sense in this case. | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | =cut | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | sub parse_file { | 
| 144 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 145 |  |  |  |  |  |  |  | 
| 146 | 0 |  |  |  |  |  | die 'makes no sence...'; | 
| 147 |  |  |  |  |  |  | } | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | 1; | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | __END__ |