| 1 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | package Template::Plugin::xkcd; | ||||||||||||
| 4 | { | ||||||||||||
| 5 | 3 | $Template::Plugin::xkcd::VERSION = '0.003'; | |||||||||||
| 6 | } | ||||||||||||
| 7 | # ABSTRACT: WWW::xkcd plugin for Template::Toolkit | ||||||||||||
| 8 | |||||||||||||
| 9 | 3 | ▶ | use base 'Template::Plugin'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 3 | ▶ | use WWW::xkcd; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | sub new { | ||||||||||||
| 13 | 3 | ▶ | my $class = shift; | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 14 | 3 | my $context = shift; | |||||||||||
| 15 | |||||||||||||
| 16 | 3 | my $self = bless { | |||||||||||
| 17 | xkcd => WWW::xkcd->new, | ||||||||||||
| 18 | }, $class; | ||||||||||||
| 19 | } | ||||||||||||
| 20 | |||||||||||||
| 21 | sub comic { | ||||||||||||
| 22 | 4 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
comic: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||
| 23 | 4 | my $num = shift; | |||||||||||
| 24 | 4 | ▶ | my $meta = $self->{'xkcd'}->fetch_metadata( $num ? $num : () ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 25 | |||||||||||||
| 26 | # return HTML | ||||||||||||
| 27 | 4 | ▶ | my $img = $meta->{'img'} || ''; | ||||||||||
|
Condition50%1/2
$meta->{'img'} || ''
MC/DC0%0/1
$meta->{'img'} || ''
$meta->{'img'}
Truth table50%1/2
A
A= $meta->{'img'}
| |||||||||||||
| 28 | 4 | ▶ | my $alt = $meta->{'alt'} || ''; | ||||||||||
|
Condition50%1/2
$meta->{'alt'} || ''
MC/DC0%0/1
$meta->{'alt'} || ''
$meta->{'alt'}
Truth table50%1/2
A
A= $meta->{'alt'}
| |||||||||||||
| 29 | |||||||||||||
| 30 | 4 | return qq{<img src="$img" alt="$alt" />}; | |||||||||||
| 31 | } | ||||||||||||
| 32 | |||||||||||||
| 33 | 3 | 1; | |||||||||||
| 34 | |||||||||||||
| 35 | |||||||||||||
| 36 | |||||||||||||
| 37 | =pod | ||||||||||||
| 38 | |||||||||||||
| 39 | =head1 NAME | ||||||||||||
| 40 | |||||||||||||
| 41 | Template::Plugin::xkcd - WWW::xkcd plugin for Template::Toolkit | ||||||||||||
| 42 | |||||||||||||
| 43 | =head1 VERSION | ||||||||||||
| 44 | |||||||||||||
| 45 | version 0.003 | ||||||||||||
| 46 | |||||||||||||
| 47 | =head1 SYNOPSIS | ||||||||||||
| 48 | |||||||||||||
| 49 | # in your template | ||||||||||||
| 50 | [% USE xkcd %] | ||||||||||||
| 51 | |||||||||||||
| 52 | <h1>xkcd comics!</h1> | ||||||||||||
| 53 | |||||||||||||
| 54 | <p>Today's xkcd comic: [% xkcd.comic %]</p> | ||||||||||||
| 55 | |||||||||||||
| 56 | <p>The 20th comic: [% xkcd.comic(20) %]</p> | ||||||||||||
| 57 | |||||||||||||
| 58 | =head1 DESCRIPTION | ||||||||||||
| 59 | |||||||||||||
| 60 | A L<Template> (Template::Toolkit) plugin to provide an image tag for xkcd | ||||||||||||
| 61 | comics. You can pick which comic (either latest, or by number). | ||||||||||||
| 62 | |||||||||||||
| 63 | It uses L<WWW::xkcd>. | ||||||||||||
| 64 | |||||||||||||
| 65 | =head1 METHODS | ||||||||||||
| 66 | |||||||||||||
| 67 | =head2 new | ||||||||||||
| 68 | |||||||||||||
| 69 | This method is used by L<Template>. | ||||||||||||
| 70 | |||||||||||||
| 71 | If you want to use this plugin, simply add the following to your template: | ||||||||||||
| 72 | |||||||||||||
| 73 | [% USE xkcd %] | ||||||||||||
| 74 | |||||||||||||
| 75 | =head2 comic | ||||||||||||
| 76 | |||||||||||||
| 77 | Fetches a comic. | ||||||||||||
| 78 | |||||||||||||
| 79 | Accept an optional argument for the number of a comic. | ||||||||||||
| 80 | |||||||||||||
| 81 | Returns an HTML <img> tag with the path and alternative text (alt text). | ||||||||||||
| 82 | |||||||||||||
| 83 | This gets the latest: | ||||||||||||
| 84 | |||||||||||||
| 85 | [% xkcd.comic %] | ||||||||||||
| 86 | |||||||||||||
| 87 | This gets the first: | ||||||||||||
| 88 | |||||||||||||
| 89 | [% xkcd.comic(1) %] | ||||||||||||
| 90 | |||||||||||||
| 91 | =head1 WHY | ||||||||||||
| 92 | |||||||||||||
| 93 | Just because. It's actually more useful than a lot of other stuff on CPAN. :) | ||||||||||||
| 94 | |||||||||||||
| 95 | =head1 AUTHOR | ||||||||||||
| 96 | |||||||||||||
| 97 | Sawyer X <xsawyerx@cpan.org> | ||||||||||||
| 98 | |||||||||||||
| 99 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 100 | |||||||||||||
| 101 | This software is copyright (c) 2012 by Sawyer X. | ||||||||||||
| 102 | |||||||||||||
| 103 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 104 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 105 | |||||||||||||
| 106 | =cut | ||||||||||||
| 107 | |||||||||||||
| 108 | |||||||||||||
| 109 | __END__ | ||||||||||||