| 1 | #! perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | package Comics::Plugin::Base; | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | Comics::Plugin::Base -- Base class for Plugins. | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | This base class is only used indirectly via the Fetchers. | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | The Plugin Base class provides tools for Plugins. | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | our $VERSION = "1.00"; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head2 register( { ... } ) | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | Registers the plugin to the aggregator. | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | The method takes a hash ref with arguments. What arguments are | ||||||||||||||||||||||||||||
| 31 | possible depends on the plugin's Fetcher type. See the documentation | ||||||||||||||||||||||||||||
| 32 | of the Fetchers for more info. | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | As of API 1.1, the preferred way of specifying the data is by using | ||||||||||||||||||||||||||||
| 35 | package variables. These will be transferred to the hash using | ||||||||||||||||||||||||||||
| 36 | introspection. | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | Common arguments are: | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =over 8 | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =item name | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | The full name of this comic, e.g. "Fokke en Sukke". | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =item url | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | The url of this comic's home page. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =item tag | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | A short identifier for this comic. This will be automatically provided | ||||||||||||||||||||||||||||
| 53 | if not specified. | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | The tag is used to generate file names for images and HTML fragments. | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =back | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =cut | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: not called CC=6 SCAR=35.4
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 0 | my ( $pkg, $init ) = @_; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # API 1.0 - change to new naming. | ||||||||||||||||||||||||||||
| 65 | 0 | $init->{pattern} = delete $init->{pat}; | |||||||||||||||||||||||||||
| 66 | 0 | $init->{patterns} = delete $init->{pats}; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # API 1.1 - fill %init with package variables. | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my %stash = do { no strict 'refs'; %{"${pkg}::"} }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 70 | # Iterate through the symbol table, which contains glob values | ||||||||||||||||||||||||||||
| 71 | # indexed by symbol names. | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | while ( my ( $var, $glob ) = each(%stash) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if (defined ${*{$glob}{SCALAR}} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | # Copy value. | ||||||||||||||||||||||||||||
| 75 | 0 | $init->{$var} = ${*{$glob}{SCALAR}}; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ( defined *{$glob}{ARRAY} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | # Copy ref. | ||||||||||||||||||||||||||||
| 79 | 0 | $init->{$var} = *{$glob}{ARRAY}; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ( defined *{$glob}{HASH} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | # Copy ref. | ||||||||||||||||||||||||||||
| 83 | 0 | $init->{$var} = *{$glob}{HASH}; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | my $self = { %$init }; | |||||||||||||||||||||||||||
| 88 | 0 | bless $self, $pkg; | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | $self->{tag} ||= $self->tag_from_package; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"tag"} ||= $self->tag_from_package
MC/DC0%0/2
$self->{"tag"} ||= $self->tag_from_package
$self->{"tag"}
$self->tag_from_package
Truth table0%0/3
A ||= B
A= $self->{"tag"}B= $self->tag_from_package
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | return $self; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head1 METHODS | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head2 html | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | Generates an HTML fragment for a fetched image. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =cut | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub html { | ||||||||||||||||||||||||||
|
Subroutine
html: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 104 | 0 | my $state = $self->{state}; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | my $w = $state->{c_width}; | |||||||||||||||||||||||||||
| 107 | 0 | my $h = $state->{c_height}; | |||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ( $h && $w ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$h and $w
MC/DC0%0/2
$h and $w
$h
$w
Truth table0%0/3
A and B
A= $hB= $w
| |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if ( $w > 1024 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | $w = 1024; | |||||||||||||||||||||||||||
| 111 | 0 | $h = int( $h * $w/$state->{c_width} ); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | my $res = | ||||||||||||||||||||||||||||
| 116 | qq{<table class="toontable" cellpadding="0" cellspacing="0">\n} . | ||||||||||||||||||||||||||||
| 117 | qq{ <tr><td nowrap align="left" valign="top">} . | ||||||||||||||||||||||||||||
| 118 | qq{<b>} . _html($self->{name}) . qq{</b><br>\n} . | ||||||||||||||||||||||||||||
| 119 | qq{ <font size="-2">Last update: } . | ||||||||||||||||||||||||||||
| 120 | 0 | localtime($state->{update}) . | |||||||||||||||||||||||||||
| 121 | qq{</font><br><br></td>\n} . | ||||||||||||||||||||||||||||
| 122 | qq{ </tr>\n <tr><td><a href="$self->{url}?$::uuid">} . | ||||||||||||||||||||||||||||
| 123 | qq{<img class="toonimage" }; | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | # Alt and title are extracted from HTML, so they should be | ||||||||||||||||||||||||||||
| 126 | # properly escaped. | ||||||||||||||||||||||||||||
| 127 | $res .= qq{alt="} . $state->{c_alt} . qq{" } | ||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if $state->{c_alt}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | $res .= qq{title="} . $state->{c_title} . qq{" } | ||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if $state->{c_title}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | $res .= qq{width="$w" height="$h" } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$w and $h
MC/DC0%0/2
$w and $h
$w
$h
Truth table0%0/3
A and B
A= $wB= $h
| |||||||||||||||||||||||||||||
| 132 | if $w && $h; | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | $res .= qq{src="$state->{c_img}"></a></td>\n </tr>\n</table>\n}; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | return $res; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | ▶ | sub _html { | ||||||||||||||||||||||||||
|
Subroutine
_html: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 140 | 0 | my ( $t ) = @_; | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | $t =~ s/&/&/g; | |||||||||||||||||||||||||||
| 143 | 0 | $t =~ s/</</g; | |||||||||||||||||||||||||||
| 144 | 0 | $t =~ s/>/>/g; | |||||||||||||||||||||||||||
| 145 | 0 | $t =~ s/"/"e;/g; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | return $t; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =head2 html | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | Generates a tag (identifier) from the name of the plugin. | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =cut | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub tag_from_package { | ||||||||||||||||||||||||||
|
Subroutine
tag_from_package: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 157 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 158 | 0 | my $tag = lc(ref($self)); | |||||||||||||||||||||||||||
| 159 | 0 | $tag =~ s/^.*:://; | |||||||||||||||||||||||||||
| 160 | 0 | return $tag; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 1 | 1; | |||||||||||||||||||||||||||