« blib/lib/Tapper/Reports/Web/Controller/Tapper/Reports/Id.pm
↑ Summary
blib/lib/Tapper/Reports/Web/Controller/Tapper/ContinuousTestruns.pm »
| 1 | package Tapper::Reports::Web::Controller::Tapper::ReportFile::Id; | ||||||||||||||||||||||||||||
| 2 | 13 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||||||||||
| 3 | 13 | $Tapper::Reports::Web::Controller::Tapper::ReportFile::Id::VERSION = '5.0.17'; | |||||||||||||||||||||||||||
| 4 | 13 | ▶ | use parent 'Tapper::Reports::Web::Controller::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use HTML::FromANSI (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | ## no critic (RequireUseStrict) | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | #use HTML::FromANSI (); # avoid exports if using OO | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 13 | our $ANSI2HTML_PRE = '<link rel="stylesheet" type="text/css" title="Red" href="/tapper/static/css/style_red.css" /><body style="background: black;">'; | |||||||||||||||||||||||||||
| 12 | 13 | our $ANSI2HTML_POST = '</body>'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub index :Path :CaptureArgs(2) | ||||||||||||||||||||||||||
|
Subroutine
index: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||
| 15 | { | ||||||||||||||||||||||||||||
| 16 | 0 | my ( $self, $c, $file_id, $viewmode ) = @_; | |||||||||||||||||||||||||||
| 17 | 0 | $c->stash->{reportfile} = $c->model('TestrunDB')->resultset('ReportFile')->find($file_id); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | if (not $c->stash->{reportfile}) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 20 | { | ||||||||||||||||||||||||||||
| 21 | 0 | $c->response->content_type ("text/plain"); | |||||||||||||||||||||||||||
| 22 | 0 | $c->response->header ("Content-Disposition" => 'inline; filename="nonexistent.reportfile.'.$file_id.'"'); | |||||||||||||||||||||||||||
| 23 | 0 | $c->response->body ("Error: File with id $file_id does not exist."); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | elsif (not $c->stash->{reportfile}->filecontent) | ||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||
| 27 | 0 | $c->response->content_type ("text/plain"); | |||||||||||||||||||||||||||
| 28 | 0 | $c->response->header ("Content-Disposition" => 'inline; filename="empty.reportfile.'.$file_id.'"'); | |||||||||||||||||||||||||||
| 29 | 0 | $c->response->body ("Error: File with id $file_id is empty."); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | else | ||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my $contenttype = $c->stash->{reportfile}->contenttype eq 'plain' ? 'text/plain' : $c->stash->{reportfile}->contenttype; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my $disposition = $contenttype =~ /plain/ ? 'inline' : 'attachment'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | $c->response->content_type ($contenttype || 'application/octet-stream'); | ||||||||||||||||||||||||||
|
Condition0%0/2
$contenttype || 'application/octet-stream'
MC/DC0%0/1
$contenttype || 'application/octet-stream'
$contenttype
Truth table0%0/2
A
A= $contenttype
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | my $filename = $c->stash->{reportfile}->filename; | |||||||||||||||||||||||||||
| 38 | 0 | my @filecontent; | |||||||||||||||||||||||||||
| 39 | my $content_disposition; | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ( $viewmode eq 'ansi2txt' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | $filename =~ s,[./],_,g if $disposition eq 'inline'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | $filename .= '.txt'; | |||||||||||||||||||||||||||
| 44 | 0 | @filecontent = ansi_to_txt($c->stash->{reportfile}->filecontent); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | } elsif ( $viewmode eq 'ansi2html' ) { | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | $filename =~ s,[./],_,g if $disposition eq 'inline'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | $filename .= '.html'; | |||||||||||||||||||||||||||
| 49 | 0 | my $a2h = HTML::FromANSI->new(style => '', font_face => ''); | |||||||||||||||||||||||||||
| 50 | 0 | @filecontent = $ANSI2HTML_PRE.$a2h->ansi_to_html($c->stash->{reportfile}->filecontent).$ANSI2HTML_POST; | |||||||||||||||||||||||||||
| 51 | 0 | $c->response->content_type('text/html'); | |||||||||||||||||||||||||||
| 52 | } else { | ||||||||||||||||||||||||||||
| 53 | 0 | @filecontent = $c->stash->{reportfile}->filecontent; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 0 | my $filecontent = join '', @filecontent; | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | $filecontent =~ s/ +$//mg if $viewmode eq 'ansi2html' or $viewmode eq 'ansi2txt'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$viewmode eq "ansi2html" or $viewmode eq "ansi2txt"
MC/DC0%0/2
$viewmode eq "ansi2html" or $viewmode eq "ansi2txt"
$viewmode eq "ansi2html"
$viewmode eq "ansi2txt"
Truth table0%0/3
A or B
A= $viewmode eq "ansi2html"B= $viewmode eq "ansi2txt"
| |||||||||||||||||||||||||||||
| 57 | 0 | $c->response->header ("Content-Disposition" => qq($disposition; filename="$filename")); | |||||||||||||||||||||||||||
| 58 | 0 | $c->response->body ($filecontent); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 13 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # strip known ANSI sequences and special characters | ||||||||||||||||||||||||||||
| 63 | # usually used in console output | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub ansi_to_txt { | ||||||||||||||||||||||||||
|
Subroutine
ansi_to_txt: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 0 | my ($filecontent) = @_; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | $filecontent =~ s/\e\[?.*?[\@-~](?:\?\d\d[hl])?//g; | |||||||||||||||||||||||||||
| 68 | 0 | $filecontent =~ s,(?:\n\r)+,\n,g; | |||||||||||||||||||||||||||
| 69 | 0 | $filecontent =~ s,\r(?!\n), ,g; | |||||||||||||||||||||||||||
| 70 | 0 | $filecontent =~ s,[]+, ,g; | |||||||||||||||||||||||||||
| 71 | 0 | return $filecontent; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | sub filter | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
filter: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 76 | 0 | my @retval; | |||||||||||||||||||||||||||
| 77 | 0 | foreach my $line (@_) { | |||||||||||||||||||||||||||
| 78 | 0 | $line =~ s/\000//g; | |||||||||||||||||||||||||||
| 79 | 0 | $line =~ s/\015//g; | |||||||||||||||||||||||||||
| 80 | 0 | $line =~ s/\033\[.*?[mH]//g; | |||||||||||||||||||||||||||
| 81 | 0 | $line =~ s/\033\d+/\t/g; | |||||||||||||||||||||||||||
| 82 | 0 | $line =~ s/\017//g; | |||||||||||||||||||||||||||
| 83 | 0 | $line =~ s/\033\[\?25h//g; | |||||||||||||||||||||||||||
| 84 | 0 | push @retval, $line; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 0 | return @retval; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 13 | 1; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | __END__ | ||||||||||||||||||||||||||||