Perlito5X/Test2/Event/Plan.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 103 CC 13 SCAR 33.8
CC
13
Cov
0%
init
72.0
callback
12.0
summary
12.0
CRAP 29.3
1 package Test2::Event::Plan;
2 use strict;
3 use warnings;
4  
5 our $VERSION = '1.302073';
6  
7  
8 BEGIN { require Test2::Event; our @ISA = qw(Test2::Event) }
9 use Test2::Util::HashBase qw{max directive reason};
10  
11 use Carp qw/confess/;
12  
13 my %ALLOWED = (
14 'SKIP' => 1,
15 'NO PLAN' => 1,
16 );
17  
18 sub init {
19 if ($_[0]->{+DIRECTIVE}) {
20 $_[0]->{+DIRECTIVE} = 'SKIP' if $_[0]->{+DIRECTIVE} eq 'skip_all';
21 $_[0]->{+DIRECTIVE} = 'NO PLAN' if $_[0]->{+DIRECTIVE} eq 'no_plan';
22  
23 confess "'" . $_[0]->{+DIRECTIVE} . "' is not a valid plan directive"
24 unless $ALLOWED{$_[0]->{+DIRECTIVE}};
25 }
26 else {
27 confess "Cannot have a reason without a directive!"
28 if defined $_[0]->{+REASON};
29  
30 confess "No number of tests specified"
31 unless defined $_[0]->{+MAX};
32  
33 confess "Plan test count '" . $_[0]->{+MAX} . "' does not appear to be a valid positive integer"
34 unless $_[0]->{+MAX} =~ m/^\d+$/;
35  
36 $_[0]->{+DIRECTIVE} = '';
37 }
38 }
39  
40 sub sets_plan {
41 my $self = shift;
42 return (
43 $self->{+MAX},
44 $self->{+DIRECTIVE},
45 $self->{+REASON},
46 );
47 }
48  
49 sub callback {
50 my $self = shift;
51 my ($hub) = @_;
52  
53 $hub->plan($self->{+DIRECTIVE} || $self->{+MAX});
54  
55 return unless $self->{+DIRECTIVE};
56  
57 $hub->set_skip_reason($self->{+REASON} || 1) if $self->{+DIRECTIVE} eq 'SKIP';
58 }
59  
60 sub terminate {
61 my $self = shift;
62 # On skip_all we want to terminate the hub
63 return 0 if $self->{+DIRECTIVE} && $self->{+DIRECTIVE} eq 'SKIP';
64 return undef;
65 }
66  
67 sub summary {
68 my $self = shift;
69 my $max = $self->{+MAX};
70 my $directive = $self->{+DIRECTIVE};
71 my $reason = $self->{+REASON};
72  
73 return "Plan is $max assertions"
74 if $max || !$directive;
75  
76 return "Plan is '$directive', $reason"
77 if $reason;
78  
79 return "Plan is '$directive'";
80 }
81  
82 1;
83  
84 __END__