Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
instanciate controller classes on request
this commit adds a new feature
- Loading branch information
Showing
3 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!perl | ||
|
||
use Test::More tests => 3, import => ['!pass']; | ||
use Dancer::Test; | ||
|
||
BEGIN { | ||
use FindBin; | ||
use lib "$FindBin::Bin/lib"; | ||
use_ok 'MyAppObj'; | ||
} | ||
|
||
response_content_is [GET => '/incr'], | ||
'1', '/incr returned 1'; | ||
|
||
response_content_is [GET => '/incr'], | ||
'2', '/incr returned 2'; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package MyAppObj; | ||
|
||
BEGIN { | ||
use Dancer ':syntax'; | ||
set plugins => { | ||
Dispatcher => { | ||
base => 'MyAppObj', | ||
boot => { | ||
MyAppObj => [ { i => 0 } ] | ||
} | ||
} | ||
}; | ||
} | ||
|
||
use Dancer::Plugin::Dispatcher; | ||
|
||
sub new { | ||
my ($class, $config) = @_; | ||
return bless $config => ref $class || $class; | ||
} | ||
|
||
sub incr { | ||
my $self = shift; | ||
++$self->{i}; | ||
} | ||
|
||
boot_classes; | ||
|
||
get '/incr' => dispatch '#incr'; | ||
|
||
1; |