line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#=============================================================================== |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# DESCRIPTION: Plosurin - Perl 5 implementation of Closure Templates |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# AUTHOR: Aliaksandr P. Zahatski, <zahatski@gmail.com> |
6
|
|
|
|
|
|
|
#=============================================================================== |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Plosurin - Perl 5 implementation of Closure Templates |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
plosurin.p5 -t perl5 -package Test test.soy > Test.pm |
15
|
|
|
|
|
|
|
perldoc Test.pm |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Plosurin - Perl 5 implementation of Closure Templates |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
package Plo::File; |
25
|
1
|
|
|
1
|
|
93883
|
use Plosurin::SoyTree; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use base 'Soy::base'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
29
|
|
|
|
|
|
|
my $class = shift; |
30
|
|
|
|
|
|
|
my $self = bless( ( $#_ == 0 ) ? shift : {@_}, ref($class) || $class ); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
#set namespace |
33
|
|
|
|
|
|
|
my $namespace = $self->{namespace}->{id}; |
34
|
|
|
|
|
|
|
foreach my $tmpl ( @{ $self->{templates} } ) { |
35
|
|
|
|
|
|
|
$tmpl->{namespace} = $namespace; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
$self; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub namespace { |
41
|
|
|
|
|
|
|
$_[0]->{namespace}->{id}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub childs { |
45
|
|
|
|
|
|
|
my $self = shift; |
46
|
|
|
|
|
|
|
return [ $self->templates ]; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 templates |
50
|
|
|
|
|
|
|
Return array of tempaltes |
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub templates { |
54
|
|
|
|
|
|
|
my $self = shift; |
55
|
|
|
|
|
|
|
@{ $self->{templates} }; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
package Plo::template; |
59
|
|
|
|
|
|
|
use strict; |
60
|
|
|
|
|
|
|
use warnings; |
61
|
|
|
|
|
|
|
use Plosurin::SoyTree; |
62
|
|
|
|
|
|
|
use base 'Soy::base'; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new { |
65
|
|
|
|
|
|
|
my $class = shift; |
66
|
|
|
|
|
|
|
bless( ( $#_ == 0 ) ? shift : {@_}, ref($class) || $class ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub body { $_[0]->{template_block}->{raw_template} } |
70
|
|
|
|
|
|
|
sub name { $_[0]->{template_block}->{start_template}->{name} } |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub comment { |
73
|
|
|
|
|
|
|
return join "\n", map { $_->{raw_str} } @{ $_[0]->{header}->{h_comment} }; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
sub params { @{ $_[0]->{header}->{h_params} } } |
76
|
|
|
|
|
|
|
sub full_name { my $self = shift; $self->{namespace} . $self->name } |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub namespace { |
79
|
|
|
|
|
|
|
$_[0]->{namespace}->{id}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#parse body and return Soy tree |
83
|
|
|
|
|
|
|
sub childs { |
84
|
|
|
|
|
|
|
my $self = shift; |
85
|
|
|
|
|
|
|
my $plo = new Plosurin::SoyTree( src => $self->body ); |
86
|
|
|
|
|
|
|
die $plo unless ref $plo; |
87
|
|
|
|
|
|
|
my $reduced = $plo->reduced_tree; |
88
|
|
|
|
|
|
|
return $reduced; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
package Plosurin; |
94
|
|
|
|
|
|
|
use strict; |
95
|
|
|
|
|
|
|
use warnings; |
96
|
|
|
|
|
|
|
use v5.10; |
97
|
|
|
|
|
|
|
our $VERSION = '0.0_2'; |
98
|
|
|
|
|
|
|
use Regexp::Grammars; |
99
|
|
|
|
|
|
|
use Plosurin::Grammar; |
100
|
|
|
|
|
|
|
use Plosurin::Context; |
101
|
|
|
|
|
|
|
use Plosurin::SoyTree; |
102
|
|
|
|
|
|
|
use Plosurin::To::Perl5; |
103
|
|
|
|
|
|
|
use Plosurin::Writer::Perl5; |
104
|
|
|
|
|
|
|
our $file = "???"; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub new { |
107
|
|
|
|
|
|
|
my $class = shift; |
108
|
|
|
|
|
|
|
bless( ( $#_ == 0 ) ? shift : {@_}, ref($class) || $class ); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub parse { |
112
|
|
|
|
|
|
|
my $self = shift; |
113
|
|
|
|
|
|
|
my $ref = shift; |
114
|
|
|
|
|
|
|
our $file = shift; |
115
|
|
|
|
|
|
|
my $r = qr{ |
116
|
|
|
|
|
|
|
<extends: Plosurin::Template::Grammar> |
117
|
|
|
|
|
|
|
<matchline> |
118
|
|
|
|
|
|
|
\A <File> \Z |
119
|
|
|
|
|
|
|
}xms; |
120
|
|
|
|
|
|
|
if ( $ref =~ $r ) { |
121
|
|
|
|
|
|
|
return {%/}->{File}; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
undef; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 as_perl5 { package=>"MyApp::Tmpl" }, $node1[, $noden] |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Export nodes as perl5 package |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
use Data::Dumper; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub as_perl5 { |
135
|
|
|
|
|
|
|
my $self = shift; |
136
|
|
|
|
|
|
|
my $opt = shift; |
137
|
|
|
|
|
|
|
return " need at least one $file" unless scalar(@_); |
138
|
|
|
|
|
|
|
my @files = map { ( ref($_) eq 'ARRAY' ) ? @{$_} : ($_) } @_; |
139
|
|
|
|
|
|
|
my @alltemplates = (); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
my $package = $opt->{package} || die " |
142
|
|
|
|
|
|
|
use as_perl5( { package => ... } ) !"; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
my $ctx = new Plosurin::Context(@files); |
145
|
|
|
|
|
|
|
my $p5 = new Plosurin::To::Perl5( |
146
|
|
|
|
|
|
|
'context' => $ctx, |
147
|
|
|
|
|
|
|
'writer' => new Plosurin::Writer::Perl5, |
148
|
|
|
|
|
|
|
'package' => $package, |
149
|
|
|
|
|
|
|
); |
150
|
|
|
|
|
|
|
$p5->start_write(); |
151
|
|
|
|
|
|
|
$p5->write(@files); |
152
|
|
|
|
|
|
|
$p5->end_write(); |
153
|
|
|
|
|
|
|
my $res = $p5->wr->{code}; |
154
|
|
|
|
|
|
|
wantarray() ? ( $res, @{ $p5->{tmpls} } ) : $res; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
1; |
158
|
|
|
|
|
|
|
__END__ |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 SEE ALSO |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Closure Templates Documentation L<http://code.google.com/closure/templates/docs/overview.html> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Perl 6 implementation L<https://github.com/zag/plosurin> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 AUTHOR |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Zahatski Aliaksandr, <zag@cpan.org> |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Copyright (C) 2011 by Zahatski Aliaksandr |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
176
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |
179
|
|
|
|
|
|
|
|