SoggyOnion::Plugin - how to extend SoggyOnion


SoggyOnion documentation Contained in the SoggyOnion distribution.

Index


Code Index:

NAME

Top

SoggyOnion::Plugin - how to extend SoggyOnion

SYNOPSIS

Top

    # sample plugin that uses a file as its resource.
    # needs a 'filename' key in the item hash in the config
    package SoggyOnion::Plugin::File;

    sub init {
        my $self = shift;
        die "I have no filename" 
            unless exists $self->{filename};
    }

    sub mod_time {
        my $self = shift;
        return [ stat $self->{filename} ]->[9];
    }

    sub content {
        open( FH, "<$self->{filename}" ) or die $!
        my $data = join('', <FH>);
        close FH;
        return $data;
    }




DESCRIPTION

Top

This is the base class for all SoggyOnion plugins.

METHODS

Top

new( $hashref )

Constructor that SoggyOnion gives a hash of information. Can be used for the plugin's own stash.

init()

This is called before we call mod_time and/or content. I use it to set the useragent in LWP::Simple in a few modules.

id()

Return the ID is used for <DIV> tags and internal caching stuff. This is a simple accessor that makes the code cleaner.

mod_time()

The default mod_time method ensures that the resource is always refreshed (cache is never used).

content()

Return XHTML content.

SEE ALSO

Top

SoggyOnion

AUTHOR

Top

Ian Langworth, <ian@cpan.org>

COPYRIGHT AND LICENSE

Top


SoggyOnion documentation Contained in the SoggyOnion distribution.
package SoggyOnion::Plugin;
use warnings;
use strict;

our $VERSION = '0.04';

sub new {
    my ( $class, $data ) = @_;
    warn "$class\::new() must be passed a hash ref" && return
        unless ref $data eq 'HASH';
    bless $data, $class;
    $data->init;
    return $data;
}

sub init { }

sub id {
    my $self = shift;
    return $self->{id};
}

sub mod_time {time}

sub content {
    qq(<p class="error">This is the output of the default plugin class. Something strange has occurred.</p>\n)
}

1;