Skip to content

Instantly share code, notes, and snippets.

@mix3
Created June 21, 2011 15:42
Show Gist options
  • Save mix3/1038137 to your computer and use it in GitHub Desktop.
Save mix3/1038137 to your computer and use it in GitHub Desktop.
MobaSiFをゴニョゴニョ
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;
--- 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);
}
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;
<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