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   494 use strict;
  52         109  
  52         1538  
3 52     52   272 use warnings;
  52         121  
  52         1430  
4              
5 52     52   258 use Carp qw/croak/;
  52         169  
  52         2905  
6 52     52   334 use Test2::Util::HashBase qw/hub _filter reason/;
  52         119  
  52         354  
7              
8 52     52   12531 use Test2::API qw/test2_stack/;
  52         116  
  52         3554  
9              
10 52     52   357 use overload '""' => \&reason, fallback => 1;
  52         113  
  52         565  
11              
12             our $VERSION = '0.000155';
13              
14             sub init {
15 109     109 0 3289 my $self = shift;
16              
17 109         678 my $reason = $self->{+REASON};
18 109 50       329 croak "The 'reason' attribute is required" unless defined $reason;
19              
20 109   66     595 my $hub = $self->{+HUB} ||= test2_stack->top;
21              
22             $self->{+_FILTER} = $hub->pre_filter(
23             sub {
24 419     419   58336 my ($active_hub, $event) = @_;
25              
26             # Turn a diag into a note
27 419 100       1878 return Test2::Event::Note->new(%$event) if ref($event) eq 'Test2::Event::Diag';
28              
29 311 100       807 if ($active_hub == $hub) {
30 299 100       2273 $event->set_todo($reason) if $event->can('set_todo');
31 299         3499 $event->add_amnesty({tag => 'TODO', details => $reason});
32 299 100       13904 $event->set_effective_pass(1) if $event->isa('Test2::Event::Ok');
33             }
34             else {
35 12         89 $event->add_amnesty({tag => 'TODO', details => $reason, inherited => 1});
36             }
37              
38 311         1803 return $event;
39             },
40 109         7418 inherit => 1,
41             todo => $reason,
42             );
43             }
44              
45             sub end {
46 165     165 1 644 my $self = shift;
47 165 100       779 my $hub = $self->{+HUB} or return;
48              
49 109         579 $hub->pre_unfilter($self->{+_FILTER});
50 109         2606 delete $self->{+HUB};
51 109         868 delete $self->{+_FILTER};
52             }
53              
54             sub DESTROY {
55 109     109   744 my $self = shift;
56 109         321 $self->end;
57             }
58              
59             1;
60              
61             __END__