line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::RenderCGI::Template; |
2
|
1
|
|
|
1
|
|
13
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
3
|
1
|
|
|
1
|
|
809
|
use CGI; |
|
1
|
|
|
|
|
24241
|
|
|
1
|
|
|
|
|
4
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
my $CGI = CGI->new ; |
6
|
|
|
|
|
|
|
#~ has _cgi => sub { CGI->new }; |
7
|
|
|
|
|
|
|
has [qw(_plugin _import _content)];# _content has coderef, |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
7
|
|
|
7
|
1
|
62
|
my $self = shift->SUPER::new(@_); |
11
|
|
|
|
|
|
|
CGI->import( |
12
|
|
|
|
|
|
|
$self->_import && ref($self->_import) eq 'ARRAY' |
13
|
7
|
50
|
33
|
|
|
53
|
? @{$self->_import} |
|
7
|
|
|
|
|
67
|
|
14
|
|
|
|
|
|
|
: (grep /\w/, split(/\s+/, $self->_import)), |
15
|
|
|
|
|
|
|
'escapeHTML', |
16
|
|
|
|
|
|
|
'-utf8', |
17
|
|
|
|
|
|
|
); |
18
|
7
|
|
|
|
|
15334
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _compile { |
23
|
7
|
|
|
7
|
|
21
|
my $self = shift; |
24
|
7
|
|
|
|
|
14
|
my ($code) = @_; |
25
|
|
|
|
|
|
|
|
26
|
7
|
|
|
|
|
842
|
$self->_content(eval <
|
27
|
|
|
|
|
|
|
sub { |
28
|
|
|
|
|
|
|
my (\$self, \$c, \$cgi) = \@_; |
29
|
|
|
|
|
|
|
undef, # может комменты придут без кода |
30
|
|
|
|
|
|
|
$code |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
CODE |
33
|
7
|
100
|
|
|
|
65
|
return $@ |
34
|
|
|
|
|
|
|
if $@; |
35
|
6
|
|
|
|
|
17
|
return $self; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _run { |
39
|
7
|
|
|
7
|
|
17
|
my ($self, $c) = @_; |
40
|
|
|
|
|
|
|
|
41
|
7
|
|
|
|
|
19
|
$self->_content->($self, $c, $CGI); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
1
|
0
|
4
|
sub esc { escapeHTML(@_) } |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub AUTOLOAD { |
47
|
0
|
|
|
0
|
|
|
my ($package, $func) = our $AUTOLOAD =~ /^(.+)::(.+)$/; |
48
|
0
|
|
|
|
|
|
my $tag = $func =~ s/_/-/gr; |
49
|
0
|
|
|
|
|
|
my $package_arg = ref $_[0]; |
50
|
1
|
|
|
1
|
|
357
|
no strict 'refs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
51
|
1
|
|
|
1
|
|
5
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
238
|
|
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
if ($package eq $package_arg) { # method |
54
|
0
|
|
|
|
|
|
my $self = shift; |
55
|
|
|
|
|
|
|
#~ if ($CGI->can($func)) { |
56
|
|
|
|
|
|
|
#~ *{"${package}::$func"} = &_cgi_meth($func, 1); |
57
|
|
|
|
|
|
|
#~ } else { # HTML tag |
58
|
0
|
|
|
|
|
|
*{"${package}::$func"} = &_cgi_tag($tag, 1); |
|
0
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#~ } |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return $self->$func(@_); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# non method |
65
|
|
|
|
|
|
|
#~ if ($CGI->can($func)) { |
66
|
|
|
|
|
|
|
#~ *$func = &_cgi_meth($func); #sub { $CGI->$func(@_); }; |
67
|
|
|
|
|
|
|
#~ } else { |
68
|
0
|
|
|
|
|
|
*$func = &_cgi_tag($tag); # sub { return &CGI::_tag_func($tag,@_); }; |
69
|
|
|
|
|
|
|
#~ } |
70
|
0
|
|
|
|
|
|
return &$func(@_); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _cgi_method { |
75
|
0
|
|
|
0
|
|
|
my $method = shift; |
76
|
0
|
|
|
|
|
|
my $flag_self = shift; |
77
|
0
|
0
|
|
0
|
|
|
return sub { my $self = shift if $flag_self; $CGI->$method(@_); }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _cgi_tag { |
82
|
0
|
|
|
0
|
|
|
my $tag = shift; |
83
|
0
|
|
|
|
|
|
my $flag_self = shift; |
84
|
0
|
0
|
|
0
|
|
|
return sub { my $self = shift if $flag_self; &CGI::_tag_func($tag,@_); }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=pod |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=encoding utf8 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Доброго всем |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 Mojolicious::Plugin::RenderCGI::Template |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
¡ ¡ ¡ ALL GLORY TO GLORIA ! ! ! |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 NAME |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Mojolicious::Plugin::RenderCGI::Template - Package for cgi-handle templates. Normally internal only using from plugin. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SYNOPSIS |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$template = Mojolicious::Plugin::RenderCGI::Template->new(...); |
104
|
|
|
|
|
|
|
my $err = $template->_compile($content); |
105
|
|
|
|
|
|
|
unless (ref $err) {...} # compile error |
106
|
|
|
|
|
|
|
my @out = eval { $template->_run($c)}; |
107
|
|
|
|
|
|
|
if ($@) {...} # runtime error |
108
|
|
|
|
|
|
|
$$output = join "\n", grep defined, @out; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 ATRIBUTES (has) |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
All atributes has hidden names because you can generate any tags. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 _plugin |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 _import |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 _content |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 METHODS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
All methods has hidden names because you can generate any tags. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 new |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Each template is a seperate object. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 _compile |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Compile template content and store coderef inside atribute B<_content> and return error string if compile fails overwise self object. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 _run |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Simply execute compiled template coderef: |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
$template->_content->($template, $c, $CGI); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 AUTOLOAD |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Will generate any tag trought CGI::_tag_func($tag,@_) |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |