| 1 | 5 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package DBIx::DR::PerlishTemplate; | ||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Scalar::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use DBIx::DR::ByteStream; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | has line_tag => (is => 'rw', isa => 'Str', default => '%'); | |||||||||||||||||||||||||||
| 12 | 3 | has open_tag => (is => 'rw', isa => 'Str', default => '<%'); | |||||||||||||||||||||||||||
| 13 | 3 | has close_tag => (is => 'rw', isa => 'Str', default => '%>'); | |||||||||||||||||||||||||||
| 14 | 3 | has quote_mark => (is => 'rw', isa => 'Str', default => '='); | |||||||||||||||||||||||||||
| 15 | 4 | has immediate_mark => (is => 'rw', isa => 'Str', default => '=='); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 14 | has sql => (is => 'ro', isa => 'Str', default => ''); | |||||||||||||||||||||||||||
| 18 | 3 | has variables => (is => 'ro', isa => 'ArrayRef'); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 3 | has template => (is => 'rw', isa => 'Str', default => ''); | |||||||||||||||||||||||||||
| 21 | 3 | has template_file => (is => 'rw', isa => 'Str', default => ''); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | has stashes => (is => 'ro', isa => 'ArrayRef'); | |||||||||||||||||||||||||||
| 24 | 3 | has pretokens => (is => 'ro', isa => 'ArrayRef'); | |||||||||||||||||||||||||||
| 25 | 4 | has prepretokens => (is => 'ro', isa => 'ArrayRef'); | |||||||||||||||||||||||||||
| 26 | 14 | has parsed_template => (is => 'ro', isa => 'Str', default => ''); | |||||||||||||||||||||||||||
| 27 | 3 | has namespace => (is => 'rw', isa => 'Str', | |||||||||||||||||||||||||||
| 28 | default => 'DBIx::DR::PerlishTemplate::Sandbox'); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 3 | has sql_utf8 => (is => 'ro', isa => 'Bool', default => 1); | |||||||||||||||||||||||||||
| 32 | 62 | ▶ | sub _render { | ||||||||||||||||||||||||||
|
Subroutine
_render: called CC=6 SCAR=19.0
| |||||||||||||||||||||||||||||
| 33 | 62 | my ($_PTPL) = @_; | |||||||||||||||||||||||||||
| 34 | 62 | my $_PTSUB; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 62 | ▶ | unless ($_PTPL->parsed_template) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 62 | $_PTSUB = $_PTPL->{parsed_template} = $_PTPL->_parse; | |||||||||||||||||||||||||||
| 38 | } else { | ||||||||||||||||||||||||||||
| 39 | 2 | $_PTSUB = $_PTPL->parsed_template; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 62 | $_PTPL->{parsed_template} = $_PTSUB; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my $esub = eval $_PTSUB; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: not called CC=1 SCAR=0.4
Subroutine
__ANON__: not called CC=1 SCAR=0.4
Subroutine
__ANON__: not called CC=1 SCAR=0.4
Subroutine
__ANON__: not called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||
| 45 | 61 | ▶ | if (my $e = $@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 8 | my $do_croak; | |||||||||||||||||||||||||||
| 47 | my $template; | ||||||||||||||||||||||||||||
| 48 | 8 | ▶ | if ($_PTPL->template_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 5 | $template = $_PTPL->template_file; | |||||||||||||||||||||||||||
| 50 | } else { | ||||||||||||||||||||||||||||
| 51 | 5 | $do_croak = 1; | |||||||||||||||||||||||||||
| 52 | 6 | $template = 'inline template'; | |||||||||||||||||||||||||||
| 53 | }; | ||||||||||||||||||||||||||||
| 54 | 8 | $e =~ s{ at .*?line (\d+)(\.\s*|,\s+.*?)?$} | |||||||||||||||||||||||||||
| 55 | 7 | [" at $template line " . ( $1 - $_PTPL->pre_lines )]gsme; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 8 | ▶ | if ($1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 8 | $e =~ s/\s*$/\n/g; | |||||||||||||||||||||||||||
| 59 | 8 | ▶ | die $e unless $do_croak; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 6 | croak $e; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | croak "$e at $template"; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 56 | $_PTPL->{sql} = ''; | |||||||||||||||||||||||||||
| 67 | 55 | $_PTPL->{variables} = []; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 56 | $esub->( @{ $_PTPL->stashes } ); | |||||||||||||||||||||||||||
| 70 | 55 | 1; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 51 | ▶ | sub render { | ||||||||||||||||||||||||||
|
Subroutine
render: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 74 | 50 | my ($self, $tpl, @args) = @_; | |||||||||||||||||||||||||||
| 75 | 51 | $self->{parsed_template} = ''; | |||||||||||||||||||||||||||
| 76 | 49 | $self->template($tpl); | |||||||||||||||||||||||||||
| 77 | 49 | $self->template_file(''); | |||||||||||||||||||||||||||
| 78 | 49 | $self->{stashes} = \@args; | |||||||||||||||||||||||||||
| 79 | 49 | $self->clean_namespace; | |||||||||||||||||||||||||||
| 80 | 50 | return $self->_render; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 16 | ▶ | sub render_file { | ||||||||||||||||||||||||||
|
Subroutine
render_file: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 84 | 15 | my ($self, $file, @args) = @_; | |||||||||||||||||||||||||||
| 85 | 13 | ▶ | croak "File '@{[ $file // 'undef' ]}' not found or readable" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$file // "undef"
MC/DC0%0/1
$file // "undef"
$file
Truth table0%0/2
A
A= $file
| |||||||||||||||||||||||||||||
| 86 | unless -r $file; | ||||||||||||||||||||||||||||
| 87 | 13 | open my $fh, '<:raw', $file; | |||||||||||||||||||||||||||
| 88 | 14 | my $data; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 14 | { local $/; $data = <$fh> } | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 13 | ▶ | utf8::decode $data if $self->sql_utf8; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 13 | $self->{parsed_template} = ''; | |||||||||||||||||||||||||||
| 95 | 13 | $self->template_file($file); | |||||||||||||||||||||||||||
| 96 | 15 | $self->template($data); | |||||||||||||||||||||||||||
| 97 | 15 | $self->{stashes} = \@args; | |||||||||||||||||||||||||||
| 98 | 13 | $self->clean_namespace; | |||||||||||||||||||||||||||
| 99 | 13 | return $self->_render; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 50 | ▶ | sub clean_prepends { | ||||||||||||||||||||||||||
|
Subroutine
clean_prepends: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 103 | 49 | my ($self) = @_; | |||||||||||||||||||||||||||
| 104 | 49 | $self->{pretokens} = []; | |||||||||||||||||||||||||||
| 105 | 51 | $self; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 50 | ▶ | sub clean_preprepends { | ||||||||||||||||||||||||||
|
Subroutine
clean_preprepends: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 109 | 65 | my ($self) = @_; | |||||||||||||||||||||||||||
| 110 | 49 | $self->{prepretokens} = []; | |||||||||||||||||||||||||||
| 111 | 49 | $self; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 270 | ▶ | sub immediate { | ||||||||||||||||||||||||||
|
Subroutine
immediate: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 116 | 269 | my ($self, $str) = @_; | |||||||||||||||||||||||||||
| 117 | 269 | ▶ | if (Scalar::Util::blessed $str) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 7 | ▶ | if ('DBIx::DR::ByteStream' eq Scalar::Util::blessed $str) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 119 | 8 | $self->{sql} .= $str->content; | |||||||||||||||||||||||||||
| 120 | } elsif ($str->can('content')) { | ||||||||||||||||||||||||||||
| 121 | 1 | $self->{sql} .= $str->content; | |||||||||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||||||||||
| 123 | 2 | croak "Can't extract content from " . Scalar::Util::blessed $str; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | } else { | ||||||||||||||||||||||||||||
| 126 | 263 | $self->{sql} .= $str; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | 269 | return DBIx::DR::ByteStream->new(''); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 65 | ▶ | sub add_bind_value { | ||||||||||||||||||||||||||
|
Subroutine
add_bind_value: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 132 | 64 | my ($self, @values) = @_; | |||||||||||||||||||||||||||
| 133 | 80 | push @{ $self->variables } => @values; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 50 | ▶ | sub quote { | ||||||||||||||||||||||||||
|
Subroutine
quote: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 138 | 49 | my ($self, $variable) = @_; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 49 | ▶ | if (Scalar::Util::blessed $variable) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 7 | ▶ | return $self->immediate($variable) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | if 'DBIx::DR::ByteStream' eq Scalar::Util::blessed $variable; | ||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 43 | $self->{sql} .= '?'; | |||||||||||||||||||||||||||
| 146 | 59 | $self->add_bind_value($variable); | |||||||||||||||||||||||||||
| 147 | 43 | return DBIx::DR::ByteStream->new(''); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 64 | ▶ | sub _parse { | ||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 151 | 61 | my ($self) = @_; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 61 | my $result = ''; | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 67 | my $immediate_mark = $self->immediate_mark; | |||||||||||||||||||||||||||
| 156 | 61 | my $quote_mark = $self->quote_mark; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 74 | ▶ | my $code_cb = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||
| 159 | 78 | my ($t) = @_; | |||||||||||||||||||||||||||
| 160 | 74 | ▶ | return unless defined $t and length $t; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $t and length $t
MC/DC0%0/2
defined $t and length $t
defined $t
length $t
Truth table33%1/3
A and B
A= defined $tB= length $t
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 73 | ▶ | if ($t =~ /^\Q$immediate_mark\E/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 13 | $result .= join '', | |||||||||||||||||||||||||||
| 164 | 'immediate(', | ||||||||||||||||||||||||||||
| 165 | substr($t, length($immediate_mark)), | ||||||||||||||||||||||||||||
| 166 | ');'; | ||||||||||||||||||||||||||||
| 167 | 13 | return; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 61 | ▶ | if ($t =~ /^\Q$quote_mark\E/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 38 | $result .= join '', | |||||||||||||||||||||||||||
| 172 | 'quote(', | ||||||||||||||||||||||||||||
| 173 | substr($t, length($quote_mark)), | ||||||||||||||||||||||||||||
| 174 | ');'; | ||||||||||||||||||||||||||||
| 175 | 41 | return; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 26 | $result .= "$t;"; # always place ';' at end of code. | |||||||||||||||||||||||||||
| 179 | 77 | }; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 315 | ▶ | my $text_cb = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 182 | 314 | my ($content) = @_; | |||||||||||||||||||||||||||
| 183 | 314 | ▶ | return unless defined $content and length $content; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $content and length $content
MC/DC50%1/2
defined $content and length $content
defined $content
length $content
Truth table66%2/3
A and B
A= defined $contentB= length $content
| |||||||||||||||||||||||||||||
| 184 | 248 | $content =~ s/'/\\'/g; | |||||||||||||||||||||||||||
| 185 | 249 | $result .= "immediate('" . $content . "');"; | |||||||||||||||||||||||||||
| 186 | 61 | }; | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 61 | $self->_parse_ep($self->template, $text_cb, $code_cb); | |||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 61 | $result = join '', | |||||||||||||||||||||||||||
| 191 | 'package ', $self->namespace, ';', | ||||||||||||||||||||||||||||
| 192 | 'BEGIN { ', | ||||||||||||||||||||||||||||
| 193 | '*quote = sub { $_PTPL->quote(@_) };', | ||||||||||||||||||||||||||||
| 194 | '*immediate = sub { $_PTPL->immediate(@_) };', | ||||||||||||||||||||||||||||
| 195 | '};', | ||||||||||||||||||||||||||||
| 196 | $self->preprepend, | ||||||||||||||||||||||||||||
| 197 | 'sub {', $self->prepend, $result, "\n}"; | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 63 | return $result; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 62 | ▶ | sub _parse_ep { | ||||||||||||||||||||||||||
|
Subroutine
_parse_ep: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 64 | my ($self, $tpl, $text_cb, $code_cb) = @_; | |||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | #--------------------------------------------------------- | ||||||||||||||||||||||||||||
| 207 | # единственные три переменные из self | ||||||||||||||||||||||||||||
| 208 | 64 | my $line_tag = $self->line_tag; | |||||||||||||||||||||||||||
| 209 | 61 | my $open_tag = $self->open_tag; | |||||||||||||||||||||||||||
| 210 | 62 | my $close_tag = $self->close_tag; | |||||||||||||||||||||||||||
| 211 | # по идее это можно было оформить в виде независимого кода | ||||||||||||||||||||||||||||
| 212 | #--------------------------------------------------------- | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 61 | my @lines = split /\n/, $tpl; | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 62 | my $st = 'text'; | |||||||||||||||||||||||||||
| 217 | 61 | my $code_text; | |||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 62 | ▶ | for (my $i = 0; $i < @lines; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 187 | local $_ = $lines[$i]; | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | CODE: | ||||||||||||||||||||||||||||
| 223 | 224 | ▶ | if ($st eq 'code') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 224 | 48 | ▶ | if (/^(.*?)\Q$close_tag\E(.*)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 43 | $_ = $2; | |||||||||||||||||||||||||||
| 226 | 44 | $code_cb->($code_text . $1); | |||||||||||||||||||||||||||
| 227 | 43 | $code_text = undef; | |||||||||||||||||||||||||||
| 228 | 43 | $st = 'text'; | |||||||||||||||||||||||||||
| 229 | 46 | goto ANYTEXT; | |||||||||||||||||||||||||||
| 230 | } else { | ||||||||||||||||||||||||||||
| 231 | 5 | $code_text .= $_; | |||||||||||||||||||||||||||
| 232 | 5 | $code_text .= "\n"; | |||||||||||||||||||||||||||
| 233 | 6 | next; | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | TEXT_BEGIN: | ||||||||||||||||||||||||||||
| 238 | 178 | ▶ | if (/^(\s*)\Q$line_tag\E(.*)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | 31 | $text_cb->($1); | |||||||||||||||||||||||||||
| 240 | 31 | ▶ | if ($i < $#lines) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | 27 | $code_cb->("$2\n"); | |||||||||||||||||||||||||||
| 242 | } else { | ||||||||||||||||||||||||||||
| 243 | 7 | $code_cb->($2); | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | 30 | next; | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | ANYTEXT: | ||||||||||||||||||||||||||||
| 249 | 190 | ▶ | if (/^(.*?)\Q$open_tag\E(.*)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | 42 | $_ = $2; | |||||||||||||||||||||||||||
| 251 | 42 | $text_cb->($1); | |||||||||||||||||||||||||||
| 252 | 42 | $code_text = ''; | |||||||||||||||||||||||||||
| 253 | 45 | $st = 'code'; | |||||||||||||||||||||||||||
| 254 | 42 | goto CODE; | |||||||||||||||||||||||||||
| 255 | } else { | ||||||||||||||||||||||||||||
| 256 | 147 | $text_cb->($_); | |||||||||||||||||||||||||||
| 257 | 148 | ▶ | $text_cb->("\n") if $i < $#lines; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | 147 | next; | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | 60 | ▶ | $text_cb->("<%" . $code_text) if defined $code_text and length $code_text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $code_text and length $code_text
MC/DC0%0/2
defined $code_text and length $code_text
defined $code_text
length $code_text
Truth table33%1/3
A and B
A= defined $code_textB= length $code_text
| |||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 297 | ▶ | sub preprepend { | ||||||||||||||||||||||||||
|
Subroutine
preprepend: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 266 | 295 | my ($self, @tokens) = @_; | |||||||||||||||||||||||||||
| 267 | 297 | ▶ | $self->{prepretokens} ||= []; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"prepretokens"} ||= []
MC/DC100%1/1
$self->{"prepretokens"} ||= []
$self->{"prepretokens"}
Truth table100%2/2
A
A= $self->{"prepretokens"}
| |||||||||||||||||||||||||||||
| 268 | 294 | ▶ | push @{ $self->prepretokens } => map "$_;\n", @tokens if @tokens; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | 295 | ▶ | return join '' => @{ $self->prepretokens } if defined wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 101 | ▶ | sub prepend { | ||||||||||||||||||||||||||
|
Subroutine
prepend: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 273 | 98 | my ($self, @tokens) = @_; | |||||||||||||||||||||||||||
| 274 | 98 | ▶ | $self->{pretokens} ||= []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"pretokens"} ||= []
MC/DC0%0/1
$self->{"pretokens"} ||= []
$self->{"pretokens"}
Truth table50%1/2
A
A= $self->{"pretokens"}
| |||||||||||||||||||||||||||||
| 275 | 102 | ▶ | push @{ $self->pretokens } => map "$_;", @tokens if @tokens; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 276 | 98 | ▶ | return join '' => @{ $self->pretokens } if defined wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 10 | ▶ | sub pre_lines { | ||||||||||||||||||||||||||
|
Subroutine
pre_lines: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 281 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 282 | 6 | my $lines = 0; | |||||||||||||||||||||||||||
| 283 | 6 | $lines += @{[ /\n/g ]} for ($self->preprepend, $self->prepend); | |||||||||||||||||||||||||||
| 284 | 6 | return $lines; | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 14 | ▶ | sub clean_prepend { | ||||||||||||||||||||||||||
|
Subroutine
clean_prepend: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 288 | 12 | my ($self) = shift; | |||||||||||||||||||||||||||
| 289 | 13 | $self->{pretokens} = []; | |||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 62 | ▶ | sub clean_namespace { | ||||||||||||||||||||||||||
|
Subroutine
clean_namespace: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 293 | 60 | my ($self) = @_; | |||||||||||||||||||||||||||
| 294 | 60 | my $sb = $self->namespace; | |||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | 5 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 297 | 60 | undef *{$sb . '::' . $_} for keys %{ $sb . '::' }; | |||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 3 | 1; | |||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | =head1 NAME | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | DBIx::DR::PerlishTemplate - template engine for L<DBIx::DR>. | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | Copyright (C) 2011 Dmitry E. Oboukhov <unera@debian.org> | ||||||||||||||||||||||||||||
| 309 | Copyright (C) 2011 Roman V. Nikolaev <rshadow@rambler.ru> | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | This program is free software, you can redistribute it and/or | ||||||||||||||||||||||||||||
| 312 | modify it under the terms of the Artistic License. | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | =cut | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||