Debian Codegraph @

cpan/Test2-Suite/lib/Test2/Workflow/Task/Group.pm

raw
1 package Test2::Workflow::Task::Group;
2 use strict;
3 use warnings;
4
5 our $VERSION = '0.000162';
6
7 use Carp qw/croak/;
8
9 use Test2::Workflow::Task::Action;
10
11 use base 'Test2::Workflow::Task';
12 use Test2::Util::HashBase qw/before after primary rand variant/;
13
14 sub init {
15 my $self = shift;
16
17 if (my $take = delete $self->{take}) {
18 $self->{$_} = delete $take->{$_} for ISO, ASYNC, TODO, SKIP;
19 $self->{$_} = $take->{$_} for FLAT, SCAFFOLD, NAME, CODE, FRAME;
20 $take->{+FLAT} = 1;
21 $take->{+SCAFFOLD} = 1;
22 }
23
24 {
25 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
26 $self->SUPER::init();
27 }
28
29 $self->{+BEFORE} ||= [];
30 $self->{+AFTER} ||= [];
31 $self->{+PRIMARY} ||= [];
32 }
33
34 sub filter {
35 my $self = shift;
36 my ($filter) = @_;
37
38 return if $self->{+IS_ROOT};
39
40 my $result = $self->SUPER::filter($filter);
41
42 my $child_ok = 0;
43 for my $c (@{$self->{+PRIMARY}}) {
44 next if $c->{+SCAFFOLD};
45 # A child matches the filter, so we should not be filtered, but also
46 # should not satisfy the filter.
47 my $res = $c->filter($filter);
48
49 # A child satisfies the filter
50 $child_ok++ if !$res || $res->{satisfied};
51 last if $child_ok;
52 }
53
54 # If the filter says we are ok
55 unless($result) {
56 # If we are a variant then allow everything under us to be run
57 return {satisfied => 1} if $self->{+VARIANT} || !$child_ok;
58
59 # Normal group
60 return;
61 }
62
63 return if $child_ok;
64
65 return $result;
66 }
67
68 1;
69
70 __END__
71
72 =pod
73
74 =encoding UTF-8
75
76 =head1 NAME
77
78 Test2::Workflow::Task::Group - Encapsulation of a group (describe).
79
80 =head1 SOURCE
81
82 The source code repository for Test2-Workflow can be found at
83 F<https://github.com/Test-More/Test2-Suite/>.
84
85 =head1 MAINTAINERS
86
87 =over 4
88
89 =item Chad Granum E<lt>[email protected]<gt>
90
91 =back
92
93 =head1 AUTHORS
94
95 =over 4
96
97 =item Chad Granum E<lt>[email protected]<gt>
98
99 =back
100
101 =head1 COPYRIGHT
102
103 Copyright 2018 Chad Granum E<lt>[email protected]<gt>.
104
105 This program is free software; you can redistribute it and/or
106 modify it under the same terms as Perl itself.
107
108 See F<http://dev.perl.org/licenses/>
109
110 =cut
111