Ask.pm

filter: Statementstmt 86.2% 50 / 58 Branchbran 43.7% 7 / 16 Conditioncond 23.0% 3 / 13 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 92.8% 13 / 14 Podpod 80.0% 4 / 5 totaltotal 69.0% 78 / 113 CC 15 SCAR 24.5
CC
15
Cov
69%
detect
22.7
instance
12.0
import
2.7
CRAP 11.6
« Ask/Clui.pm ↑ Summary Ask/API.pm »
1 5 ▶use 5.008008;
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 Ask;
6  
7 5 our $AUTHORITY = 'cpan:TOBYINK';
8 5 our $VERSION = '0.015';
9  
10 5 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Moo::Role qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Module::Runtime qw(use_module use_package_optimistically);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Module::Pluggable (
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 search_path => 'Ask',
15 except => [qw/ Ask::API Ask::Functions Ask::Question /],
16 inner => 0,
17 require => 0,
18 sub_name => '__plugins',
19 5 );
20 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 5 ▶sub import {
Subroutine import: called CC=2 SCAR=10.1
23 5 shift;
24 5 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 5 5
25 0 require Ask::Functions;
26 0 unshift @_, 'Ask::Functions';
27 0 goto( $_[0]->can( 'import' ) );
28 }
29 }
30  
31 3 ▶sub plugins {
Subroutine plugins: called CC=1 SCAR=0.0
Pod documented
32 3 __plugins( @_ );
33 }
34  
35 3 ▶sub backends {
Subroutine backends: called CC=1 SCAR=0.0
Pod documented
36 3 my $class = shift;
37 30 sort { $b->quality <=> $a->quality }
38 grep {
39 3 eval { use_package_optimistically( $_ )->DOES( 'Ask::API' ) }
40 } $class->plugins;
41 }
42  
43 3 ▶sub detect {
Subroutine detect: called CC=12 SCAR=31.2
Pod documented
44 3 my $class = shift;
45 0 ▶ my %args = @_ == 1 ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 3 3
46
47 3 my @implementations = $class->backends;
48
49 3 ▶ if ( exists $ENV{PERL_ASK_BACKEND} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $ENV{'PERL_ASK_BACKEND'}) { } 3 0 3
elsif ($ENV{'AUTOMATED_TESTING'} or $ENV{'PERL_MM_USE_DEFAULT'} or not @implementations) { } 0 0 0
50 3 @implementations = use_module( $ENV{PERL_ASK_BACKEND} );
51 }
52 ▶ elsif ( $ENV{AUTOMATED_TESTING}
Condition0%0/6
$ENV{"AUTOMATED_TESTING"} or $ENV{"PERL_MM_USE_DEFAULT"} or not @implementations
l!l&&r!l&&!r
000
$ENV{"AUTOMATED_TESTING"} or $ENV{"PERL_MM_USE_DEFAULT"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$ENV{"AUTOMATED_TESTING"} or $ENV{"PERL_MM_USE_DEFAULT"} or not @implementations
$ENV{"AUTOMATED_TESTING"} $ENV{"PERL_MM_USE_DEFAULT"} not @implementations
Truth table0%0/4
A or B or not(C)
A= $ENV{"AUTOMATED_TESTING"}B= $ENV{"PERL_MM_USE_DEFAULT"}C= not @implementations
ABCresult
1XX1
01X1
0011
0000
53 or $ENV{PERL_MM_USE_DEFAULT}
54 or not @implementations )
55 {
56 0 @implementations = use_module( 'Ask::Fallback' );
57 }
58
59 3 ▶ my @traits = @{ delete( $args{traits} ) || [] };
Condition100%2/2
delete $args{'traits'} || []
l!l
12
MC/DC100%1/1
delete $args{'traits'} || []
delete $args{'traits'}
Truth table100%2/2
A
A= delete $args{'traits'}
Aresult
11
00
60 3 for my $i ( @implementations ) {
61 3 ▶ my $k = @traits ? "Moo::Role"->create_class_with_roles( $i, @traits ) : $i;
Branch: 1 branch
BranchTrueFalseTotal
@traits ? : 1 2 3
62 3 ▶ my $self = eval { $k->new( { %args, %{ $args{$i} or {} } } ) } or next;
Branch: 1 branch
BranchTrueFalseTotal
my $self = eval { do { $k->new({%args, %{$args{$i} or {};}}) } } or next 3 0 3
Condition50%1/2
$args{$i} || {}
l!l
03
MC/DC0%0/1
$args{$i} || {}
$args{$i}
Truth table50%1/2
A
A= $args{$i}
Aresult
11
00
63 3 ▶ return $self if $self->is_usable;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_usable 3 0 3
64 }
65
66 0 croak "No usable backend for Ask";
67 } #/ sub detect
68  
69 1 ▶sub Q {
Subroutine Q: called CC=1 SCAR=0.0
Pod undocumented
70 1 require Ask::Question;
71 1 'Ask::Question'->new( @_ );
72 }
73  
74 5 my $instance;
75 0 ▶sub instance {
Subroutine instance: not called CC=3 SCAR=24.8
Pod documented
76 0 shift;
77 0 ▶ @_ ? ( $instance = $_[0] ) : ( $instance ||= __PACKAGE__->detect );
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
Condition0%0/3
$instance ||= __PACKAGE__->detect
l!l&&r!l&&!r
000
MC/DC0%0/2
$instance ||= __PACKAGE__->detect
$instance __PACKAGE__->detect
Truth table0%0/3
A ||= B
A= $instanceB= __PACKAGE__->detect
ABresult
1X1
011
000
78 }
79  
80 5 1;
81  
82 __END__
« Ask/Clui.pm ↑ Summary Ask/API.pm »