Backbone/Dispatcher/PredicateIterator.pm

filter: Statementstmt 100% 22 / 22 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 100% 34 / 34 CC 2 SCAR 2.2
CC
2
Cov
100%
next_predicate
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« Backbone/Service/Role/Chat.pm ↑ Summary Backbone/Identity.pm »
1 package Bot::Backbone::Dispatcher::PredicateIterator;
2 4 $Bot::Backbone::Dispatcher::PredicateIterator::VERSION = '0.142220';
3 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Bot::Backbone::Types qw( PredicateList );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # ABSTRACT: Iterator over the predicates in a dispatcher
9  
10  
11 4 has dispatcher => (
12 is => 'ro',
13 isa => 'Bot::Backbone::Dispatcher',
14 required => 1,
15 );
16  
17 has predicate_list => (
18 is => 'rw',
19 isa => PredicateList,
20 required => 1,
21 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
22 4 traits => [ 'Array' ],
23 handles => {
24 have_more_predicates => 'count',
25 next_from_predicate_list => 'shift',
26 add_predicates => 'push',
27 },
28 );
29  
30  
31 sub BUILD {
32 1 ▶ my $self = shift;
Subroutine BUILD: called CC=1 SCAR=0.0
Pod documented
33 1 $self->reset;
34 }
35  
36  
37 sub next_predicate {
38 5 ▶ my $self = shift;
Subroutine next_predicate: called CC=2 SCAR=6.9
Pod documented
39  
40 5 ▶ return unless $self->have_more_predicates;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->have_more_predicates 1 4 5
41  
42 4 my $predicate = $self->next_from_predicate_list;
43 4 $self->add_predicates($predicate->more_predicates);
44  
45 4 return $predicate;
46 }
47  
48  
49 sub reset {
50 1 ▶ my $self = shift;
Subroutine reset: called CC=1 SCAR=0.0
Pod documented
51  
52 1 $self->predicate_list([
53 $self->dispatcher->list_predicates,
54 $self->dispatcher->list_also_predicates,
55 ]);
56 }
57  
58 4 __PACKAGE__->meta->make_immutable;
59  
60 __END__
61  
62 =pod
63  
64 =encoding UTF-8
65  
66 =head1 NAME
67  
68 Bot::Backbone::Dispatcher::PredicateIterator - Iterator over the predicates in a dispatcher
69  
70 =head1 VERSION
71  
72 version 0.142220
73  
74 =head1 SYNOPSIS
75  
76 my $iterator = $dispatcher->predicate_iterator;
77 while (my $predicate = $iterator->next_predicate) {
78 # do something...
79 }
80  
81 =head1 DESCRIPTION
82  
83 This is a helper for iterating over predicates in a L<Bot::Backbone::Dispatcher>.
84  
85 =head1 ATTRIBUTES
86  
87 =head2 dispatcher
88  
89 This is the dispatcher this iterator iterates over.
90  
91 =head1 METHODS
92  
93 =head2 BUILD
94  
95 Resets the iterator to the start at construction.
96  
97 =head2 next_predicate
98  
99 Returns the next L<Bot::Backbone::Dispatcher::Predicate> or C<undef> if all predicates have been iterated through.
100  
101 =head2 reset
102  
103 Starts over by retriving the list of predicates that belong to the associated L<Bot::Backbone::Dispatcher>.
104  
105 =head1 AUTHOR
106  
107 Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
108  
109 =head1 COPYRIGHT AND LICENSE
110  
111 This software is copyright (c) 2014 by Qubling Software LLC.
112  
113 This is free software; you can redistribute it and/or modify it under
114 the same terms as the Perl 5 programming language system itself.
115  
116 =cut
« Backbone/Service/Role/Chat.pm ↑ Summary Backbone/Identity.pm »