blib/lib/Template/Plugin/xkcd.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 21 | 21 | 100.0 |
branch | 2 | 2 | 100.0 |
condition | 2 | 4 | 50.0 |
subroutine | 6 | 6 | 100.0 |
pod | 2 | 2 | 100.0 |
total | 33 | 35 | 94.2 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | 2 | 2 | 90375 | use strict; | |||
2 | 13 | ||||||
2 | 118 | ||||||
2 | 2 | 2 | 11 | use warnings; | |||
2 | 4 | ||||||
2 | 188 | ||||||
3 | package Template::Plugin::xkcd; | ||||||
4 | { | ||||||
5 | $Template::Plugin::xkcd::VERSION = '0.003'; | ||||||
6 | } | ||||||
7 | # ABSTRACT: WWW::xkcd plugin for Template::Toolkit | ||||||
8 | |||||||
9 | 2 | 2 | 11 | use base 'Template::Plugin'; | |||
2 | 5 | ||||||
2 | 1831 | ||||||
10 | 2 | 2 | 8124 | use WWW::xkcd; | |||
2 | 322993 | ||||||
2 | 444 | ||||||
11 | |||||||
12 | sub new { | ||||||
13 | 3 | 3 | 1 | 6834 | my $class = shift; | ||
14 | 3 | 7 | my $context = shift; | ||||
15 | |||||||
16 | 3 | 24 | my $self = bless { | ||||
17 | xkcd => WWW::xkcd->new, | ||||||
18 | }, $class; | ||||||
19 | } | ||||||
20 | |||||||
21 | sub comic { | ||||||
22 | 4 | 4 | 1 | 1050 | my $self = shift; | ||
23 | 4 | 11 | my $num = shift; | ||||
24 | 4 | 100 | 42 | my $meta = $self->{'xkcd'}->fetch_metadata( $num ? $num : () ); | |||
25 | |||||||
26 | # return HTML | ||||||
27 | 4 | 50 | 634524 | my $img = $meta->{'img'} || ''; | |||
28 | 4 | 50 | 27 | my $alt = $meta->{'alt'} || ''; | |||
29 | |||||||
30 | 4 | 78 | return qq{}; | ||||
31 | } | ||||||
32 | |||||||
33 | 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 | xkcd comics! |
||||||
53 | |||||||
54 | Today's xkcd comic: [% xkcd.comic %] |
||||||
55 | |||||||
56 | The 20th comic: [% xkcd.comic(20) %] |
||||||
57 | |||||||
58 | =head1 DESCRIPTION | ||||||
59 | |||||||
60 | A L (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 |
||||||
64 | |||||||
65 | =head1 METHODS | ||||||
66 | |||||||
67 | =head2 new | ||||||
68 | |||||||
69 | This method is used by L. | ||||||
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 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 |
||||||
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__ |