| 1 | package Tapper::Reports::API; | ||||||||||||||||||||||||||||
| 2 | # git description: v5.0.4-1-ga161e06 | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 11 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: Tapper - Remote network API for result evaluation | ||||||||||||||||||||||||||||
| 6 | 11 | $Tapper::Reports::API::VERSION = '5.0.5'; | |||||||||||||||||||||||||||
| 7 | 11 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use parent 'Net::Server::Fork'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use Tapper::Reports::DPath::Mason; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 11 | ▶ | use Tapper::Reports::DPath::TT; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 11 | ▶ | use Tapper::Model 'model'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | sub process_request | ||||||||||||||||||||||||||||
| 20 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
process_request: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 6 | my $cmdline = <STDIN>; | |||||||||||||||||||||||||||
| 24 | 6 | my ($cmd, @args) = _split_cmdline( $cmdline ); | |||||||||||||||||||||||||||
| 25 | 11 | ▶ | no strict 'refs'; ## no critic (ProhibitNoStrict) | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 6 | ▶ | $cmd //= "TAP"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$cmd //= "TAP"
MC/DC0%0/1
$cmd //= "TAP"
$cmd
Truth table50%1/2
A
A= $cmd
| |||||||||||||||||||||||||||||
| 27 | 6 | my $handle = "handle_$cmd"; | |||||||||||||||||||||||||||
| 28 | 6 | $self->$handle (@args); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub handle_TAP | ||||||||||||||||||||||||||||
| 33 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
handle_TAP: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | #print STDERR "Unrecognized input, interpret as TAP, but: TAP reporting via this API not yet implemented\n"; | ||||||||||||||||||||||||||||
| 37 | 0 | print STDERR "Unrecognized input.\n"; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | sub handle_download | ||||||||||||||||||||||||||||
| 42 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
handle_download: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 4 | my ($self, $report_id, $filename, $index) = @_; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 4 | ▶ | $index ||= 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$index ||= 0
MC/DC100%1/1
$index ||= 0
$index
Truth table100%2/2
A
A= $index
| |||||||||||||||||||||||||||||
| 46 | 4 | ▶ | my $asc_desc = $index < 0 ? '-desc' : '-asc'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 4 | $index = abs $index; | |||||||||||||||||||||||||||
| 48 | 4 | my %reportfilter = (); | |||||||||||||||||||||||||||
| 49 | 4 | ▶ | $reportfilter{report_id} = $report_id if $report_id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 4 | my $reportfile = | |||||||||||||||||||||||||||
| 51 | model('TestrunDB') | ||||||||||||||||||||||||||||
| 52 | ->resultset('ReportFile') | ||||||||||||||||||||||||||||
| 53 | ->search ({ %reportfilter, | ||||||||||||||||||||||||||||
| 54 | filename => { like => $filename } }, | ||||||||||||||||||||||||||||
| 55 | { order_by => { $asc_desc => 'id' } }) | ||||||||||||||||||||||||||||
| 56 | ->slice($index, $index)->first; | ||||||||||||||||||||||||||||
| 57 | 4 | ▶ | print $reportfile->filecontent if $reportfile; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | sub get_payload | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_payload: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # unite '<<' and EOFMARKER when whitespace separated, in order to fix confusion | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | $args[-2] .= pop @args if $args[-2] && $args[-2] eq '<<'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args[-2] and $args[-2] eq "<<"
MC/DC0%0/2
$args[-2] and $args[-2] eq "<<"
$args[-2]
$args[-2] eq "<<"
Truth table0%0/3
A and B
A= $args[-2]B= $args[-2] eq "<<"
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | my $EOFMARKER; | |||||||||||||||||||||||||||
| 69 | 0 | ▶ | $EOFMARKER = $1 if $args[-1] =~ /<<(.*)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | return '' unless $EOFMARKER; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # ----- read template ----- | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | my $line; | |||||||||||||||||||||||||||
| 75 | 0 | my $payload = ''; | |||||||||||||||||||||||||||
| 76 | 0 | ▶ | while ($line = <STDIN>) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | last if ($line =~ /^$EOFMARKER\s*$/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | $payload .= $line; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 0 | return $payload; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | sub handle_tt | ||||||||||||||||||||||||||||
| 87 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
handle_tt: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 1 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | do { print "Template Toolkit is not enabled\n"; return } unless Tapper::Config->subconfig->{reports_enable_tt}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 1 | my %args = _parse_args(@args[0..$#args-1]); | |||||||||||||||||||||||||||
| 92 | 1 | my $payload = $self->get_payload(@args); | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | my $tt = Tapper::Reports::DPath::TT->new ( | ||||||||||||||||||||||||||||
| 95 | debug => $args{debug} ? 1 : 0, | ||||||||||||||||||||||||||||
| 96 | 1 | ▶ | puresqlabstract => $args{puresqlabstract} ? 1 : 0, | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||
| 98 | 1 | my $answer = $tt->render(template => $payload); | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 1 | print $answer; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | sub handle_upload | ||||||||||||||||||||||||||||
| 105 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
handle_upload: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 106 | 2 | my ($self, $report_id, $filename, $contenttype) = @_; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 2 | my $s_filecontent = ''; | |||||||||||||||||||||||||||
| 109 | 2 | $s_filecontent = do { local $/; <STDIN> }; | |||||||||||||||||||||||||||
| 110 | 2 | ▶ | return model('TestrunDB')->resultset('ReportFile')->new({ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$contenttype || 'plain'
MC/DC0%0/1
$contenttype || 'plain'
$contenttype
Truth table50%1/2
A
A= $contenttype
| |||||||||||||||||||||||||||||
| 111 | report_id => $report_id, | ||||||||||||||||||||||||||||
| 112 | filename => $filename, | ||||||||||||||||||||||||||||
| 113 | filecontent => $s_filecontent, | ||||||||||||||||||||||||||||
| 114 | contenttype => $contenttype || 'plain', # 'application/octet-stream', | ||||||||||||||||||||||||||||
| 115 | })->insert if length($s_filecontent); | ||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 2 | ▶ | sub _parse_args { | ||||||||||||||||||||||||||
|
Subroutine
_parse_args: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 119 | 2 | my (@args) = @_; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 2 | my %args = (); | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 2 | foreach (@args) { | |||||||||||||||||||||||||||
| 124 | 3 | my ($k, $v) = split /=/; | |||||||||||||||||||||||||||
| 125 | 3 | $k =~ s/^-+//; | |||||||||||||||||||||||||||
| 126 | 3 | $args{$k} = $v; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | 2 | return %args; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | sub handle_mason | ||||||||||||||||||||||||||||
| 133 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
handle_mason: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 134 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 135 | 0 | ▶ | do { print "Mason is not enabled. Set reports_enable_mason: 1 in ".Tapper::Config->subconfig->{_last_used_tapper_config_file}.".\n"; return } unless Tapper::Config->subconfig->{reports_enable_mason}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | my %args = _parse_args(@args[0..$#args-1]); | |||||||||||||||||||||||||||
| 138 | 0 | my $payload = $self->get_payload(@args); | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | my $mason = Tapper::Reports::DPath::Mason->new ( | ||||||||||||||||||||||||||||
| 141 | debug => $args{debug} ? 1 : 0, | ||||||||||||||||||||||||||||
| 142 | 0 | ▶ | puresqlabstract => $args{puresqlabstract} ? 1 : 0, | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 143 | ); | ||||||||||||||||||||||||||||
| 144 | 0 | my $answer = $mason->render(template => $payload); | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | print $answer; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | sub _split_cmdline | ||||||||||||||||||||||||||||
| 150 | 22 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_split_cmdline: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 151 | 22 | my ($cmdline) = @_; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 22 | $cmdline =~ s/^\s+//; | |||||||||||||||||||||||||||
| 154 | 22 | my @list = split (/\s+/, $cmdline); | |||||||||||||||||||||||||||
| 155 | 22 | shift @list; # no shebang | |||||||||||||||||||||||||||
| 156 | 22 | return @list; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | sub post_process_request_hook | ||||||||||||||||||||||||||||
| 161 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
post_process_request_hook: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 162 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 11 | 1; # End of Tapper::Reports::API | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | __END__ | ||||||||||||||||||||||||||||