| 1 | package Mojolicious::Plugin::RenderCGI::Template; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Mojo::Base -base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use CGI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | my $CGI = CGI->new ; | |||||||||||||||||||||||||||
| 6 | #~ has _cgi => sub { CGI->new }; | ||||||||||||||||||||||||||||
| 7 | 1 | has [qw(_plugin _import _content)];# _content has coderef, | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 7 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 10 | 7 | my $self = shift->SUPER::new(@_); | |||||||||||||||||||||||||||
| 11 | CGI->import( | ||||||||||||||||||||||||||||
| 12 | $self->_import && ref($self->_import) eq 'ARRAY' | ||||||||||||||||||||||||||||
| 13 | 7 | ▶ | ? @{$self->_import} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->_import and ref $self->_import eq "ARRAY"
MC/DC0%0/2
$self->_import and ref $self->_import eq "ARRAY"
$self->_import
ref $self->_import eq "ARRAY"
Truth table33%1/3
A and B
A= $self->_importB= ref $self->_import eq "ARRAY"
| |||||||||||||||||||||||||||||
| 14 | : (grep /\w/, split(/\s+/, $self->_import)), | ||||||||||||||||||||||||||||
| 15 | 'escapeHTML', | ||||||||||||||||||||||||||||
| 16 | '-utf8', | ||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||
| 18 | 7 | return $self; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 7 | ▶ | sub _compile { | ||||||||||||||||||||||||||
|
Subroutine
_compile: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 23 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 24 | 7 | my ($code) = @_; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 7 | $self->_content(eval <<CODE); | |||||||||||||||||||||||||||
| 27 | sub { | ||||||||||||||||||||||||||||
| 28 | my (\$self, \$c, \$cgi) = \@_; | ||||||||||||||||||||||||||||
| 29 | undef, # может комменты придут без кода | ||||||||||||||||||||||||||||
| 30 | $code | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | CODE | ||||||||||||||||||||||||||||
| 33 | 7 | ▶ | return $@ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | if $@; | ||||||||||||||||||||||||||||
| 35 | 6 | return $self; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 8 | ▶ | sub _run { | ||||||||||||||||||||||||||
|
Subroutine
_run: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 8 | my ($self, $c) = @_; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 8 | $self->_content->($self, $c, $CGI); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1 | ▶ | sub esc { escapeHTML(@_) } | ||||||||||||||||||||||||||
|
Subroutine
esc: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=2 SCAR=11.6
| |||||||||||||||||||||||||||||
| 47 | 0 | my ($package, $func) = our $AUTOLOAD =~ /^(.+)::(.+)$/; | |||||||||||||||||||||||||||
| 48 | 0 | my $tag = $func =~ s/_/-/gr; | |||||||||||||||||||||||||||
| 49 | 0 | my $package_arg = ref $_[0]; | |||||||||||||||||||||||||||
| 50 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | 1 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($package eq $package_arg) { # method | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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); | |||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub _cgi_method { | ||||||||||||||||||||||||||
|
Subroutine
_cgi_method: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 75 | 0 | my $method = shift; | |||||||||||||||||||||||||||
| 76 | 0 | my $flag_self = shift; | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | return sub { my $self = shift if $flag_self; $CGI->$method(@_); }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub _cgi_tag { | ||||||||||||||||||||||||||
|
Subroutine
_cgi_tag: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 82 | 0 | my $tag = shift; | |||||||||||||||||||||||||||
| 83 | 0 | my $flag_self = shift; | |||||||||||||||||||||||||||
| 84 | 0 | ▶ | return sub { my $self = shift if $flag_self; &CGI::_tag_func($tag,@_); }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 1; | |||||||||||||||||||||||||||