Skip to content

Instantly share code, notes, and snippets.

@taiyoh
Created August 10, 2009 11:01
Show Gist options
  • Save taiyoh/165132 to your computer and use it in GitHub Desktop.
Save taiyoh/165132 to your computer and use it in GitHub Desktop.
use Test::Base;
plan 'no_plan';
{
package T;
use Ark;
package T::MyActionClass;
use Mouse::Role;
sub execute {
my $orig = shift;
my ($self, $c, @args) = @_;
$c->res->body('before');
$orig->(@_);
$c->res->body($c->res->body . 'after');
}
package T::MyActionClass2;
use Mouse::Role;
sub execute {
my $result = shift->(@_);
return "$result, hoge";
}
package Ark::ActionClass::MyAction;
use Mouse::Role;
sub execute {
my $orig = shift;
my ($self, $c, @args) = @_;
$c->res->body('before');
$orig->(@_);
$c->res->body($c->res->body . 'after');
}
package T::Controller::Root;
use Ark 'Controller';
has '+namespace' => default => '';
sub index :Path :Args(0) :ActionClass('+T::MyActionClass') {
my ($self, $c) = @_;
$c->res->body( $c->res->body . 'action' );
}
sub index2 :Local :Args(0) :ActionClass('MyAction') {
my ($self, $c) = @_;
$c->res->body( $c->res->body . 'action' );
}
sub normal :Local :Args(0) {
my ($self, $c) = @_;
$c->res->body( $c->res->body . 'action' );
}
sub index3 :Local :Args(0) {
my ($self, $c) = @_;
my $content = $c->forward('pmethod');
$c->res->body( $c->res->body . $content );
}
sub pmethod :Private :ActionClass('+T::MyActionClass2') {
my ($self, $c) = @_;
return 'pmethod';
}
}
use Ark::Test 'T', components => [
qw/MyActionClass Controller::Root/
];
is(get('/'), 'beforeactionafter', q{:ActionClass('+T::MyActionClass') ok});
is(get('/index2'), 'beforeactionafter', q{:ActionClass('MyAction') ok});
is(get('/index3'), 'pmethod, hoge', q{:ActionClass('+T::MyActionClass2') ok});
is(get('/normal'), 'action', 'without :ActionClass');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment