Apache2-WebApp-Toolkit

 view release on metacpan or  search on metacpan

lib/Apache2/WebApp/Plugin.pm  view on Meta::CPAN

#----------------------------------------------------------------------------+
#
#  Apache2::WebApp::Plugin - Base class for WebApp Toolkit plugins
#
#  DESCRIPTION
#  A simple mechanism for loading WebApp Toolkit plugins.
#
#  AUTHOR
#  Marc S. Brooks <mbrooks@cpan.org>
#
#  This module is free software; you can redistribute it and/or
#  modify it under the same terms as Perl itself.
#
#----------------------------------------------------------------------------+

package Apache2::WebApp::Plugin;

use strict;
use warnings;
use base 'Apache2::WebApp::Base';
use Params::Validate qw( :all );

our $VERSION = 0.03;
our $AUTOLOAD;

#~~~~~~~~~~~~~~~~~~~~~~~~~~[  OBJECT METHODS  ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

#----------------------------------------------------------------------------+
# load($name)
#
# Include the class (plugin('class')) if it hasn't already been included.

sub load {
    my ($self, $name)
      = validate_pos(@_,
          { type => OBJECT },
          { type => SCALAR }
      );

    $name =~ s/\b(\w)/\u$1/g;

    my $package = "Apache2::WebApp::Plugin::$name";

    unless ( $package->can('isa') ) {
        eval "require $package";

        $self->error("Failed to load package '$package': $@") if $@;
    }

    if ( $package->can('new') ) {
        $self->{ uc($name) } = $package->new;
    }

    return $self->{ uc($name) };
}

#----------------------------------------------------------------------------+
# AUTOLOAD()
#
# Provides pseudo-methods for read-only access to various internal methods.
 
sub AUTOLOAD {
    my $self = shift;
    my $method;
    ($method = $AUTOLOAD) =~ s/.*:://g;
    return if ($method eq 'DESTROY');
    return $self->{ uc($method) };
}

1;

__END__

=head1 NAME

Apache2::WebApp::Plugin - Base class for WebApp Toolkit plugins

=head1 SYNOPSIS

  my $obj = $c->plugin('Name')->method( ... );     # Apache2::WebApp::Plugin::Name->method

    or

  $c->plugin('Name')->method( ... );

=head1 DESCRIPTION

A simple mechanism for loading WebApp Toolkit plugins.

=head1 PLUGINS

There are many plugins that provide additional functionality to your web application.

L<Apache2::WebApp::Plugin::CGI> - Common methods for dealing with HTTP requests.



( run in 4.077 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )