| blib/lib/SoggyOnion/Plugin.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % |
| statement | 6 | 16 | 37.5 |
| branch | 0 | 2 | 0.0 |
| condition | 0 | 2 | 0.0 |
| subroutine | 2 | 7 | 28.5 |
| pod | 5 | 5 | 100.0 |
| total | 13 | 32 | 40.6 |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package SoggyOnion::Plugin; | ||||||
| 2 | 1 | 1 | 6 | use warnings; | |||
| 1 | 13 | ||||||
| 1 | 46 | ||||||
| 3 | 1 | 1 | 6 | use strict; | |||
| 1 | 2 | ||||||
| 1 | 241 | ||||||
| 4 | |||||||
| 5 | our $VERSION = '0.04'; | ||||||
| 6 | |||||||
| 7 | =head1 NAME | ||||||
| 8 | |||||||
| 9 | SoggyOnion::Plugin - how to extend SoggyOnion | ||||||
| 10 | |||||||
| 11 | =head1 SYNOPSIS | ||||||
| 12 | |||||||
| 13 | # sample plugin that uses a file as its resource. | ||||||
| 14 | # needs a 'filename' key in the item hash in the config | ||||||
| 15 | package SoggyOnion::Plugin::File; | ||||||
| 16 | |||||||
| 17 | sub init { | ||||||
| 18 | my $self = shift; | ||||||
| 19 | die "I have no filename" | ||||||
| 20 | unless exists $self->{filename}; | ||||||
| 21 | } | ||||||
| 22 | |||||||
| 23 | sub mod_time { | ||||||
| 24 | my $self = shift; | ||||||
| 25 | return [ stat $self->{filename} ]->[9]; | ||||||
| 26 | } | ||||||
| 27 | |||||||
| 28 | sub content { | ||||||
| 29 | open( FH, "<$self->{filename}" ) or die $! | ||||||
| 30 | my $data = join('', |
||||||
| 31 | close FH; | ||||||
| 32 | return $data; | ||||||
| 33 | } | ||||||
| 34 | |||||||
| 35 | |||||||
| 36 | =head1 DESCRIPTION | ||||||
| 37 | |||||||
| 38 | This is the base class for all SoggyOnion plugins. | ||||||
| 39 | |||||||
| 40 | =head1 METHODS | ||||||
| 41 | |||||||
| 42 | =head2 new( $hashref ) | ||||||
| 43 | |||||||
| 44 | Constructor that SoggyOnion gives a hash of information. Can be used for the | ||||||
| 45 | plugin's own stash. | ||||||
| 46 | |||||||
| 47 | =cut | ||||||
| 48 | |||||||
| 49 | sub new { | ||||||
| 50 | 0 | 0 | 1 | my ( $class, $data ) = @_; | |||
| 51 | 0 | 0 | 0 | warn "$class\::new() must be passed a hash ref" && return | |||
| 52 | unless ref $data eq 'HASH'; | ||||||
| 53 | 0 | bless $data, $class; | |||||
| 54 | 0 | $data->init; | |||||
| 55 | 0 | return $data; | |||||
| 56 | } | ||||||
| 57 | |||||||
| 58 | =head2 init() | ||||||
| 59 | |||||||
| 60 | This is called before we call mod_time and/or content. I use it to set the | ||||||
| 61 | useragent in LWP::Simple in a few modules. | ||||||
| 62 | |||||||
| 63 | =cut | ||||||
| 64 | |||||||
| 65 | 0 | 0 | 1 | sub init { } | |||
| 66 | |||||||
| 67 | =head2 id() | ||||||
| 68 | |||||||
| 69 | Return the ID is used for tags and internal caching stuff. This is |
||||||
| 70 | a simple accessor that makes the code cleaner. | ||||||
| 71 | |||||||
| 72 | =cut | ||||||
| 73 | |||||||
| 74 | sub id { | ||||||
| 75 | 0 | 0 | 1 | my $self = shift; | |||
| 76 | 0 | return $self->{id}; | |||||
| 77 | } | ||||||
| 78 | |||||||
| 79 | =head2 mod_time() | ||||||
| 80 | |||||||
| 81 | The default mod_time method ensures that the resource is always refreshed | ||||||
| 82 | (cache is never used). | ||||||
| 83 | |||||||
| 84 | =cut | ||||||
| 85 | |||||||
| 86 | 0 | 0 | 1 | sub mod_time {time} | |||
| 87 | |||||||
| 88 | =head2 content() | ||||||
| 89 | |||||||
| 90 | Return XHTML content. | ||||||
| 91 | |||||||
| 92 | =cut | ||||||
| 93 | |||||||
| 94 | sub content { | ||||||
| 95 | 0 | 0 | 1 | qq( This is the output of the default plugin class. Something strange has occurred. \n) |
|||
| 96 | } | ||||||
| 97 | |||||||
| 98 | =head1 SEE ALSO | ||||||
| 99 | |||||||
| 100 | L |
||||||
| 101 | |||||||
| 102 | =head1 AUTHOR | ||||||
| 103 | |||||||
| 104 | Ian Langworth, C<< |
||||||
| 105 | |||||||
| 106 | =head1 COPYRIGHT AND LICENSE | ||||||
| 107 | |||||||
| 108 | Copyright (C) 2004 by Ian Langworth | ||||||
| 109 | |||||||
| 110 | This library is free software; you can redistribute it and/or modify | ||||||
| 111 | it under the same terms as Perl itself. | ||||||
| 112 | |||||||
| 113 | =cut | ||||||
| 114 | |||||||
| 115 | 1; | ||||||
| 116 |