File Coverage

blib/lib/Test2/Todo.pm
Criterion Covered Total %
statement 38 38 100.0
branch 11 12 91.6
condition 2 3 66.6
subroutine 10 10 100.0
pod 1 2 50.0
total 62 65 95.3


line stmt bran cond sub pod time code
1             package Test2::Todo;
2 52     52   373 use strict;
  52         143  
  52         1544  
3 52     52   272 use warnings;
  52         98  
  52         1468  
4              
5 52     52   302 use Carp qw/croak/;
  52         110  
  52         2543  
6 52     52   310 use Test2::Util::HashBase qw/hub _filter reason/;
  52         88  
  52         335  
7              
8 52     52   12767 use Test2::API qw/test2_stack/;
  52         121  
  52         3607  
9              
10 52     52   447 use overload '""' => \&reason, fallback => 1;
  52         230  
  52         507  
11              
12             our $VERSION = '0.000156';
13              
14             sub init {
15 108     108 0 2566 my $self = shift;
16              
17 108         595 my $reason = $self->{+REASON};
18 108 50       285 croak "The 'reason' attribute is required" unless defined $reason;
19              
20 108   66     400 my $hub = $self->{+HUB} ||= test2_stack->top;
21              
22             $self->{+_FILTER} = $hub->pre_filter(
23             sub {
24 405     405   47605 my ($active_hub, $event) = @_;
25              
26             # Turn a diag into a note
27 405 100       1611 return Test2::Event::Note->new(%$event) if ref($event) eq 'Test2::Event::Diag';
28              
29 298 100       769 if ($active_hub == $hub) {
30 294 100       1679 $event->set_todo($reason) if $event->can('set_todo');
31 294         3107 $event->add_amnesty({tag => 'TODO', details => $reason});
32 294 100       10819 $event->set_effective_pass(1) if $event->isa('Test2::Event::Ok');
33             }
34             else {
35 4         67 $event->add_amnesty({tag => 'TODO', details => $reason, inherited => 1});
36             }
37              
38 298         1279 return $event;
39             },
40 108         8168 inherit => 1,
41             todo => $reason,
42             );
43             }
44              
45             sub end {
46 161     161 1 591 my $self = shift;
47 161 100       737 my $hub = $self->{+HUB} or return;
48              
49 108         522 $hub->pre_unfilter($self->{+_FILTER});
50 108         2085 delete $self->{+HUB};
51 108         723 delete $self->{+_FILTER};
52             }
53              
54             sub DESTROY {
55 108     108   824 my $self = shift;
56 108         234 $self->end;
57             }
58              
59             1;
60              
61             __END__