NAME
Blosxom::Plugin - Base class for Blosxom plugins
SYNOPSIS
package my_plugin;
use strict;
use warnings;
use parent 'Blosxom::Plugin';
# generates a class attribute called foo()
__PACKAGE__->mk_accessors( 'foo' );
# does Blosxom::Plugin::DataSection
__PACKAGE__->load_components( 'DataSection' );
sub start {
my $class = shift;
$class->foo( 'bar' );
my $value = $class->foo; # => "bar"
my $template = $class->get_data_section( 'my_plugin.html' );
# <!DOCTYPE html>
# ...
# merge __DATA__ into Blosxom default templates
$class->merge_data_section_into( \%blosxom::template );
return 1;
}
1;
__DATA__
@@ my_plugin.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My Plugin</title>
</head>
<body>
<h1>Hello, world</h1>
</body>
</html>
DESCRIPTION
Base class for Blosxom plugins. Inspired by Blosxom 3 which was abandoned to be released.
BACKGROUND
Blosxom globalizes a lot of variables. This module assigns them to appropriate namespaces like 'Request', 'Response' or 'Config'. In addition, it's intended that Blosxom::Plugin::* namespace will abstract routines from Blosxom plugins.
METHODS
- $class->mk_accessors( @fields )
- $class->mk_accessors( $field => \&default, ... )
-
This creates class attributes for each named field given in
@fields
. Attributes can have default values which is not generated until the field is read.&default
is called as a method on the class with no additional parameters.package my_plugin; use parent 'Blosxom::Plugin'; use Path::Class::File; __PACKAGE__->mk_accessors( 'path', 'file' => sub { my $class = shift; Path::Class::File->new( $class->path ); }, ); sub start { my $class = shift; $class->path( '/path/to/entry.txt' ); my $path = $class->path; # => "/path/to/entry.txt" # file() is a Path::Class::File object my $basename = $class->file->basename; # => "entry.txt" return 1; }
- $class->load_components( @components )
- $class->load_components( $component => \%configuration, ... )
-
Loads the given components into the current module. Components can be configured by the loaders. If a module begins with a
+
character, it is taken to be a fully qualified class name, otherwiseBlosxom::Plugin
is prepended to it.__PACKAGE__->load_components( '+MyComponent' => \%config );
This method calls
init()
method of each component.init()
is called as follows:MyComponent->init( 'my_plugin', \%config )
- $class->add_method( $method_name )
- $class->add_method( $method_name => $coderef )
-
This method takes a method name and a subroutine reference, and adds the method to the class. Available while loading components. If the caller's class defines a method which has the same name as
$method_name
,$coderef
can be ommited.package MyComponent; sub init { my ( $class, $context, $config ) = @_; $context->add_method( 'foo' ); $context->add_method( 'bar' => sub { ... } ); } sub foo { my $class = shift; ... }
If a method is already defined on the class, that method will not be composed in from the component. If multiple components are applied in a single call, then if any of their provided methods clash, an exception is raised unless the class provides the method.
- $class->add_attribute( $field )
- $class->add_attribute( $field => \&builder )
-
This method takes an attribute name, and adds the attribute to the class. Available while loading components. Attributes can have default values which is not generated until the field is read.
\&builder
is called as a method on the class with no additional parameters.sub init { my ( $class, $context ) = @_; $context->add_attribute( 'foo' ); $context->add_attribute( 'bar' => sub { ... } ); }
- $bool = $class->has_method( $method_name )
-
Returns a Boolean value telling whether or not the class defines the named method. It does not include methods inherited from parent classes.
my $requires = 'bar'; sub init { my ( $class, $context ) = @_; unless ( $context->has_method($requires) ) { die "Cannot apply '$class' to '$context'"; } }
- $class->end
-
Undefines class attributes generated by
mk_accessors()
oradd_attribute()
. Sinceend()
is one of recognized hooks, it's guaranteed that Blosxom always invokes this method.sub end { my $class = shift; # do something $class->SUPER::end; }
DEPENDENCIES
Blosxom 2.0.0 or higher.
SEE ALSO
Blosxom::Plugin::Web, Amon2, Moose::Manual::Roles, MooseX::Role::Parameterized::Tutorial
ACKNOWLEDGEMENT
Blosxom was originally written by Rael Dohnfest. The Blosxom Development Team succeeded to the maintenance.
BUGS AND LIMITATIONS
This module is beta state. API may change without notice.
AUTHOR
Ryo Anazawa <anazawa@cpan.org>
LICENSE AND COPYRIGHT
Copyright (c) 2012 Ryo Anzawa. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.