Created
March 8, 2016 16:40
-
-
Save s1037989/835469a14fd164cc6161 to your computer and use it in GitHub Desktop.
helpers in Mojo::Template
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
use 5.022; | |
use lib 'lib'; | |
use B; | |
say B->new->render('a.txt'); | |
package A; | |
use Mojo::Base -base; | |
use Mojo::Loader 'data_section'; | |
use Mojo::Template; | |
has test => 123; | |
sub render { | |
my $self = shift; | |
my $mt = Mojo::Template->new(vars=>1)->namespace(__PACKAGE__) | |
->render(data_section(ref $self, shift), {time => time}); | |
} | |
1; | |
package B; | |
use Mojo::Base 'A'; | |
helper abc => sub { shift->test }; | |
1; | |
__DATA__ | |
@@ a.txt | |
hi <%= time %> | |
hi <%= $time %> | |
hi <%= test %> ... 123 | |
hi <%= abc %> ... 123 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment