| 1 | package Mojolicious::Plugin::Prove::Controller; | ||||||||||||||||||||||||||||
| 2 | 8 | $Mojolicious::Plugin::Prove::Controller::VERSION = '0.11'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Controller for Mojolicious::Plugin::Prove | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use Mojo::Base 'Mojolicious::Controller'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use App::Prove; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use Mojo::File qw(path); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use Capture::Tiny qw(capture); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 7 | ▶ | sub list { | ||||||||||||||||||||||||||
|
Subroutine
list: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 7 | my $conf = $self->stash->{conf}; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 7 | my $name = $self->param( 'name' ); | |||||||||||||||||||||||||||
| 17 | 7 | ▶ | if ( $name && !exists $conf->{$name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$name and not exists $conf->{$name}
MC/DC100%2/2
$name and not exists $conf->{$name}
$name
not exists $conf->{$name}
Truth table100%3/3
A and not(B)
A= $nameB= not exists $conf->{$name}
| |||||||||||||||||||||||||||||
| 18 | 2 | $self->render( 'prove_exception' ); | |||||||||||||||||||||||||||
| 19 | 2 | return; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 5 | ▶ | if ( $name ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | my $files = path( $conf->{$name} ) | ||||||||||||||||||||||||||||
| 24 | ->list | ||||||||||||||||||||||||||||
| 25 | 2 | ▶ | ->grep( sub { $_->extname eq 't' } ) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | ->map( sub { $_->basename } ) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | ->to_array; | |||||||||||||||||||||||||||
| 28 | 1 | $self->stash( files => $files ); | |||||||||||||||||||||||||||
| 29 | 1 | $self->stash( names => '' ); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | else { | ||||||||||||||||||||||||||||
| 32 | 4 | $self->stash( name => '' ); | |||||||||||||||||||||||||||
| 33 | 4 | $self->stash( names => [ keys %{$conf} ] ); | |||||||||||||||||||||||||||
| 34 | 4 | $self->stash( files => '' ); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 5 | $self->render( 'prove_file_list' ); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 5 | ▶ | sub file { | ||||||||||||||||||||||||||
|
Subroutine
file: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 5 | my $file = $self->param( 'file' ); | |||||||||||||||||||||||||||
| 44 | 5 | my $name = $self->param( 'name' ); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 5 | $self->stash( format => 'html' ); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 5 | my $conf = $self->stash->{conf}; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 5 | ▶ | if ( !exists $conf->{$name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 1 | $self->render( 'prove_exception' ); | |||||||||||||||||||||||||||
| 52 | 1 | return; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | my $found = path( $conf->{$name} ) | ||||||||||||||||||||||||||||
| 56 | ->list | ||||||||||||||||||||||||||||
| 57 | 8 | ▶ | ->grep( sub { $_->extname eq 't' and $file eq $_->basename } ) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 4 | ->first; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 4 | ▶ | if ( !$found ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 2 | $self->render( 'prove_exception' ); | |||||||||||||||||||||||||||
| 62 | 2 | return; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | my $content = $found->slurp; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 2 | $self->stash( code => $content ); | |||||||||||||||||||||||||||
| 68 | 2 | $self->stash( file => $file ); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 2 | $self->render( 'prove_file' ); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 8 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 8 | my $file = $self->param( 'file' ); | |||||||||||||||||||||||||||
| 77 | 8 | my $name = $self->param( 'name' ); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 8 | my $conf = $self->stash->{conf}; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 8 | ▶ | if ( !exists $conf->{$name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 2 | $self->render( 'prove_exception' ); | |||||||||||||||||||||||||||
| 83 | 2 | return; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | my $files = path( $conf->{$name} ) | ||||||||||||||||||||||||||||
| 87 | ->list | ||||||||||||||||||||||||||||
| 88 | 12 | ▶ | ->grep( sub { $_->extname eq 't' } ) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 89 | 12 | ▶ | ->map( sub { [ $_->basename, $_->to_string ] } ) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 90 | 6 | ->to_array; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 6 | my $found; | |||||||||||||||||||||||||||
| 93 | 6 | ▶ | if ( $file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 3 | ▶ | ($found) = grep{ $file eq $_->[0] } @{$files || []}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$files || []
MC/DC0%0/1
$files || []
$files
Truth table50%1/2
A
A= $files
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 3 | ▶ | if ( !$found ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 1 | $self->render( 'prove_exception' ); | |||||||||||||||||||||||||||
| 98 | 1 | return; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 5 | ▶ | my @args = $found ? $found : @{ $files || [] }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$files || []
MC/DC0%0/1
$files || []
$files
Truth table50%1/2
A
A= $files
| |||||||||||||||||||||||||||||
| 103 | 5 | @args = sort map{ $_->[1] } @args; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 5 | local $ENV{HARNESS_TIMER}; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 5 | ▶ | my $accepts = $self->app->renderer->accepts( $self )->[0] // 'html'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->app->renderer->accepts($self)->[0] // "html"
MC/DC100%1/1
$self->app->renderer->accepts($self)->[0] // "html"
$self->app->renderer->accepts($self)->[0]
Truth table100%2/2
A
A= $self->app->renderer->accepts($self)->[0]
| |||||||||||||||||||||||||||||
| 108 | 5 | ▶ | my $format = $accepts =~ m{\Ahtml?} ? 'html' : $accepts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 5 | my $prove = App::Prove->new; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 5 | $prove->process_args( '--norc', @args ); | |||||||||||||||||||||||||||
| 113 | 5 | ▶ | $prove->formatter('TAP::Formatter::HTML') if $format eq 'html'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 5 | ▶ | my ($stdout, $stderr, @result) = capture { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 116 | 5 | $prove->run; | |||||||||||||||||||||||||||
| 117 | 5 | }; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 5 | ▶ | if ( $format eq 'html' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 1 | $stdout =~ s{\A.*?^(<!DOCTYPE)}{$1}xms; | |||||||||||||||||||||||||||
| 121 | 1 | $self->render( text => $stdout ); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | else { | ||||||||||||||||||||||||||||
| 124 | 4 | $self->tx->res->headers->content_type('text/plain'); | |||||||||||||||||||||||||||
| 125 | 4 | $self->render( text => $stdout ); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 8 | 1; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||||||||||