Apache2-Controller
view release on metacpan or search on metacpan
lib/Apache2/Controller.pm view on Meta::CPAN
=head2 a2c_new
$handler = MyApp::C::ControllerSubclass->a2c_new( Apache2::RequestRec object )
This is called by handler() to create the Apache2::Controller object
via the module chosen by your L<Apache2::Controller::Dispatch> subclass.
We use C<< a2c_new >> instead of the conventional C<< new >>
because, in case you want to suck in the L<Apache2::Request>
methods with that module's automagic, then you don't get
confused about how C<<SUPER::>> behaves. Otherwise you
get into a mess of keeping track of the order of bases
so you don't call C<< Apache2::Request->new() >> by accident,
which breaks everything.
=head3 subclassing C<a2c_new()>
To set params for the L<Apache2::Request> object,
you have to subclass C<a2c_new()>.
package MyApp::ControllerBase;
use base qw( Apache2::Controller Apache2::Request );
sub a2c_new {
my ($class, $r) = @_;
return SUPER::new(
$class, $r,
POST_MAX => 65_535,
TEMP_DIR => '/dev/shm',
);
# $self is already blessed in the class hierarchy
}
package MyApp::Controller::SomeURI;
use base qw( MyApp::ControllerBase );
sub allowed_methods qw( uri_one uri_two );
lib/Apache2/Controller.pm view on Meta::CPAN
If you need to do the same stuff every time a request
starts, you can override the constructor through a
class hierarchy.
package MyApp::ControllerBase;
use base qw( Apache2::Controller Apache2::Request );
sub new {
my ($class, $r, @apr_override_args) = @_;
my $self = SUPER::new(
$class, $r,
POST_MAX => 65_535,
TEMP_DIR => '/dev/shm',
@apr_override_args,
);
# $self is already blessed in the class hierarchy
# do request-startup stuff common to all controller modules
return $self;
}
package MyApp::Controller::SomeURI;
use base qw( MyApp::ControllerBase );
sub allowed_methods qw( uri_one uri_two );
sub new {
my ($class, $r) = @_;
my $self = SUPER::a2c_new(
$class, $r,
);
# no need to bless, A2C blesses into the child class
# do request-startup stuff for this specific controller
return $self;
}
lib/Apache2/Controller/Render/Template.pm view on Meta::CPAN
}
sub default {
# ...
}
=head1 STASH FUNCTIONS
We don't assign any stash functions by default.
If you want to assign consistent stash functions in your controller,
overload C<< render() >>, assign them, and then call C<< SUPER::render() >>.
package MyApp::ControllerBase;
use base qw( Apache2::Controller Apache2::Controller::Render::Template );
use HTML::Entities;
sub render {
my ($self) = @_;
$self->{stash}{encode_entities} = \&encode_entities;
$self->SUPER::render();
}
package MyApp::Controller::Somewhere;
use base qw( MyApp::ControllerBase );
# ...
sub someuri {
my ($self, @path_args) = @_;
$self->render();
return Apache2::Const::HTTP_OK;
}
t/lib/Apache2/Controller/Test/TestRun.pm view on Meta::CPAN
use base qw( Apache::TestRunPerl );
use Apache::TestConfig;
use Log::Log4perl qw(:easy);
use Apache2::Controller::Test::UnitConf qw( $L4P_UNIT_CONF );
# after starting the httpd, set up the logs
sub start {
my ($self) = @_;
$self->SUPER::start();
Log::Log4perl->init(\$L4P_UNIT_CONF);
}
sub bug_report {
my ($self) = @_;
print <<EOI;
+-----------------------------------------------------------------------+
| Apache2::Controller - framework for Apache2 apps |
| Please file a bug report with CPAN RT: |
t/lib/TestApp/Render/ControllerBase.pm view on Meta::CPAN
Apache2::Request
);
use YAML::Syck;
use Log::Log4perl qw(:easy);
sub render {
my ($self) = @_;
DEBUG "Assigning Dump() to stash";
$self->{stash}{Dump} = \&Dump;
return $self->SUPER::render();
}
1;
( run in 1.266 second using v1.01-cache-2.11-cpan-49f99fa48dc )