web/cgi-bin/yatt.lib/YATT/Translator/Perl/macro_dbfetch.pm

filter: Statementstmt 16.6% 9 / 54 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 66.6% 2 / 3 Podpod 0.0% 0 / 1 totaltotal 11.7% 11 / 94 CC 17 SCAR 56.1
CC
17
Cov
10%
macro
306.0
BEGIN
1.0
BEGIN
1.0
CRAP 273.9
↑ Summary web/cgi-bin/yatt.lib/YATT/Toplevel/CGI.pm »
1 package YATT::Translator::Perl::macro_dbfetch;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 require YATT::Translator::Perl;
5  
6 1 YATT::Translator::Perl::make_arg_spec
7 (\ my %arg_dict, \ my @arg_order, qw(row sth table schema));
8  
9 0 ▶sub macro {
Subroutine macro: not called CC=17 SCAR=57.2
Pod undocumented
10 0 my ($trans, $scope, $args) = @_;
11 0 my $orig_node = $args->clone;
12 my @hash_spec
13 0 = $trans->feed_arg_or_make_hash_of(text => $scope, $args
14 , \%arg_dict, \@arg_order
15 , my ($rowVarName
16 , $sth, $table, $schema));
17  
18 0 ▶ unless ($table) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($table) 0 0 0
19 0 die $trans->node_error($orig_node->parent, "table= is missing");
20 }
21  
22 0 my %local;
23 0 ▶ my $sthVar = $sth ? node_body($sth) : 'sth';
Branch: 1 branch
BranchTrueFalseTotal
$sth ? : 0 0 0
24 0 $local{$sthVar} = $trans->create_var('scalar' => $args
25 , varname => $sthVar);
26 0 my ($loop, $else);
27 0 my $found = my $header = $args->variant_builder;
28 0 ▶ for (; $args->readable; $args->next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->readable) 0 0 0
29 0 ▶ unless ($args->is_attribute) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->is_attribute) 0 0 0
30 0 $found->add_node($args->current);
31 0 next;
32 }
33 0 ▶ if ($args->node_name eq 'row') { # XXX: body でも良いのでは?
Branch: 2 branches
BranchTrueFalseTotal
if ($args->node_name eq 'row') { } 0 0 0
elsif ($args->node_name eq 'else') { } 0 0 0
34 0 $loop = $args->open;
35 0 $found = $args->variant_builder;
36 } elsif ($args->node_name eq 'else') {
37 0 $else = $args->open;
38 0 last;
39 } else {
40 }
41 }
42 0 my @columns;
43 my %inner;
44 0 ▶ if ($loop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loop) { } 0 0 0
45 0 ▶ for (; $loop->readable && $loop->is_primary_attribute; $loop->next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loop->readable and $loop->is_primary_attribute) 0 0 0
Condition0%0/3
$loop->readable and $loop->is_primary_attribute
!ll&&!rl&&r
000
MC/DC0%0/2
$loop->readable and $loop->is_primary_attribute
$loop->readable $loop->is_primary_attribute
Truth table0%0/3
A and B
A= $loop->readableB= $loop->is_primary_attribute
ABresult
0X0
100
111
46 0 my ($name, $typename) = $trans->arg_name_types($loop);
47 0 ▶ $inner{$name} = $trans->create_var
Condition0%0/2
$typename || 'text'
l!l
00
MC/DC0%0/1
$typename || 'text'
$typename
Truth table0%0/2
A
A= $typename
Aresult
11
00
48 ($typename || 'text', $loop, varname => $name);
49 0 my $expr = $loop->node_body;
50 # [varName => columnExpr]
51 0 ▶ push @columns, [$name => defined $expr ? "$expr as $name" : $name];
Branch: 1 branch
BranchTrueFalseTotal
defined $expr ? : 0 0 0
52 }
53 } else {
54 }
55  
56 0 my ($fetchMode, $rowVarExpr) = do {
57 0 ▶ if (@columns) {
Branch: 1 branch
BranchTrueFalseTotal
if (@columns) { } 0 0 0
58 0 (array => '('.join(", ", map {'$'.$_->[0]} @columns).')')
59 } else {
60 0 ▶ my $name = $rowVarName ? node_body($rowVarName) : 'row';
Branch: 1 branch
BranchTrueFalseTotal
$rowVarName ? : 0 0 0
61 0 $local{$name} = $trans->create_var('list' => $args
62 , varname => $name);
63 0 (hashref => '$'.$name);
64 }
65 };
66  
67 0 my $loopBody = do {
68 0 ▶ if ($loop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loop) { } 0 0 0
69 0 $trans->as_block
70 ($trans->as_statement_list
71 ($trans->generate_body([\%inner, [\%local, $scope]], $loop)));
72 } else {
73 0 die "NIMPL";
74 }
75 };
76  
77 # XXX: Static check! (But, to check, quoted expression is too much!)
78 0 my $schemaExpr = $trans->default_gentype
79 (DBSchema => text => $scope, $args, $schema);
80  
81 0 my $tableExpr = $trans->faked_gentype
82 (text => $scope, $args, $table);
83  
84 my $prepare = sprintf(q|my $%s = $this->%s->to_fetch(%s, %s, %s)|
85 , $sthVar
86 , $schemaExpr
87 , $tableExpr
88 , (@columns ?
89 ('['.join(", ", map {
90 0 YATT::Translator::Perl::qparen($_->[1])
91 } @columns).']')
92 : 'undef')
93 0 ▶ , join(", ", map {"$_->[0] => $_->[1]"}
Branch: 1 branch
BranchTrueFalseTotal
@columns ? : 0 0 0
94 @hash_spec));
95  
96 0 my $if = sprintf(q|if (my %1$s) {%2$s; do %3$s while (%1$s); %4$s}|
97 , sprintf(q|%s = $%s->fetchrow_%s|
98 , $rowVarExpr, $sthVar, $fetchMode)
99 , $trans->as_statement_list
100 ($trans->generate_body([\%local, $scope], $header))
101 , $loopBody
102 , $trans->as_statement_list
103 ($trans->generate_body([\%local, $scope], $found))
104 );
105 0 ▶ $if .= " else ".$trans->as_block
Branch: 1 branch
BranchTrueFalseTotal
if $else 0 0 0
106 ($trans->as_statement_list
107 ($trans->generate_body([\%local, $scope], $else))) if $else;
108  
109 0 \ "{$prepare; $if}";
110 }
111  
112 1 1;
↑ Summary web/cgi-bin/yatt.lib/YATT/Toplevel/CGI.pm »