/
Plugin.pm
54 lines (40 loc) · 947 Bytes
/
Plugin.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package Moxy::Plugin;
use strict;
use warnings;
use base qw/Class::Component::Plugin/;
use YAML;
use Path::Class;
use Carp;
use Template;
sub assets_path {
my ($proto, $context) = @_;
croak "argument \$context missing" unless ref $context;
my $module = ref $proto || $proto;
$module =~ s/^Moxy::Plugin:://;
$module =~ s/::/-/g;
dir($context->assets_path, 'plugins', $module);
}
sub render_template {
my ($self, $context, $fname, $args) = @_;
my $tt = Template->new(
ABSOLUTE => 1,
ENCODING => 'utf8',
);
$tt->process(
$self->assets_path($context)->file($fname)->stringify,
$args,
\my $output
) or die $tt->error;
return $output;
}
1;
__END__
=head1 NAME
Moxy::Plugin - abstract base class of Moxy plugin
=head1 DESCRIPTION
This is abstract base class of Moxy plugins.
=head1 AUTHOR
Kan Fushihara
Tokuhiro Matsuno
=head1 SEE ALSO
L<Moxy>