File Coverage

inc/Test2/Event/Plan.pm
Criterion Covered Total %
statement 26 39 66.6
branch 6 24 25.0
condition 2 11 18.1
subroutine 8 10 80.0
pod 4 5 80.0
total 46 89 51.6


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