Apache-Action
view release on metacpan or search on metacpan
lib/Apache/Action.pm view on Meta::CPAN
package Apache::Action;
use strict;
use vars qw($VERSION @ISA %ACTIONS);
use Carp;
use Exporter;
use Data::Dumper;
use Apache::Constants qw(:response);
$VERSION = 0.02;
@ISA = qw(Exporter);
# Class methods
sub register {
my $self = shift;
my $app = shift;
my $module = shift;
my $actions = ($#_ == 0) ? { %{ (shift) } } : { @_ };
my ($package) = caller;
foreach (keys %$actions) {
my $val = $actions->{$_};
my $subref;
if (ref($val) eq 'CODE') {
# val is a coderef
$subref = $val;
}
elsif (ref($val)) {
die "Cannot use reference to " . ref($val) .
" as an action routine.";
}
else {
no strict qw(refs);
my $subref = ($val =~ /::/)
? \&{"$val"}
: \&{"$package\::$val"};
die "No such subroutine " . $val
unless $subref;
}
$ACTIONS{$app}->{$module}->{$_} = $subref;
}
}
# Instance methods
sub new {
my $class = shift;
my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ };
die "No Request in Apache::Action" unless $self->{Request};
die "No Session in Apache::Action" unless $self->{Session};
die "No State in Apache::Action" unless $self->{State};
$self->{Errors} = [ ];
return bless $self, $class;
}
sub run {
my ($self) = @_;
my $httparg = $self->param('action');
$self->param('action', undef);
return OK unless length($httparg);
my ($app, $module, $action) = split("/", $httparg);
( run in 1.526 second using v1.01-cache-2.11-cpan-aadc1410aed )