Created
June 21, 2011 15:42
-
-
Save mix3/1038137 to your computer and use it in GitHub Desktop.
MobaSiFをゴニョゴニョ
This file contains hidden or 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
package Context; | |
use Any::Moose; | |
has stash => ( | |
is => 'rw', | |
isa => 'HashRef', | |
lazy => 1, | |
default => sub { {} }, | |
); | |
has template => ( | |
is => 'rw', | |
isa => 'Str', | |
lazy => 1, | |
default => '', | |
); | |
sub render { | |
my $self = shift; | |
my $html = HTMLTemplate::insert($self->template, $self->stash); | |
Response::output(\$html); | |
} | |
__PACKAGE__->meta->make_immutable; |
This file contains hidden or 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
--- pm/Page/Main.pm.orig 2011-06-22 09:19:20.000000000 +0900 | |
+++ pm/Page/Main.pm 2011-06-22 09:51:48.000000000 +0900 | |
@@ -247,7 +247,15 @@ | |
my $moduleFile = "$moduleName.pm"; | |
$moduleFile =~ s#::#/#g; | |
require $moduleFile; | |
- &{"$moduleName\::$subName"}($func); | |
+ | |
+ (my $moduleName_ = $moduleName) =~ s!::!/!g; | |
+ $moduleName_ =~ s!Page/!!g; | |
+ my $template = lc($moduleName_).'/'.$subName; | |
+ require Context; | |
+ my $c = Context->new(template => $template); | |
+ &{"$moduleName\::$subName"}($c); | |
+ $c->render; | |
+ #&{"$moduleName\::$subName"}($func); | |
} |
This file contains hidden or 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
package Page::Sample; | |
use strict; | |
use HTMLTemplate; | |
use Response; | |
sub test { | |
my $c = shift; | |
$c->stash->{message} = 'test'; | |
} | |
sub test1 { | |
my $c = shift; | |
$c->stash->{message} = 'test1'; | |
$c->template('sample/test'); | |
} | |
sub test2 { | |
my $c = shift; | |
$c->stash->{message} = 'test2'; | |
$c->stash->{list} = [ | |
{lv => 1}, | |
{lv => 2}, | |
{lv => 3}, | |
]; | |
$c->template('sample/test'); | |
} | |
1; |
This file contains hidden or 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
<html> | |
<head><title>$CON:title$</title></head> | |
<body> | |
$INC:small$ | |
message: $=h:message$<br> | |
$ if (list) { $ | |
<p> | |
$ loop (list) { $ | |
lv: $=h:lv$<br> | |
$ } $ | |
</p> | |
$ } $ | |
$INC:/small$ | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment