File Coverage

blib/lib/Bot/Backbone/Dispatcher/PredicateIterator.pm
Criterion Covered Total %
statement 9 18 50.0
branch 0 2 0.0
condition n/a
subroutine 3 6 50.0
pod 3 3 100.0
total 15 29 51.7


line stmt bran cond sub pod time code
1             package Bot::Backbone::Dispatcher::PredicateIterator;
2             $Bot::Backbone::Dispatcher::PredicateIterator::VERSION = '0.142820';
3 3     3   28 use v5.10;
  3         7  
  3         105  
4 3     3   13 use Moose;
  3         5  
  3         15  
5              
6 3     3   14908 use Bot::Backbone::Types qw( PredicateList );
  3         6  
  3         19  
7              
8             # ABSTRACT: Iterator over the predicates in a dispatcher
9              
10              
11             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             default => sub { [] },
22             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 0     0 1   my $self = shift;
33 0           $self->reset;
34             }
35              
36              
37             sub next_predicate {
38 0     0 1   my $self = shift;
39              
40 0 0         return unless $self->have_more_predicates;
41              
42 0           my $predicate = $self->next_from_predicate_list;
43 0           $self->add_predicates($predicate->more_predicates);
44              
45 0           return $predicate;
46             }
47              
48              
49             sub reset {
50 0     0 1   my $self = shift;
51              
52 0           $self->predicate_list([
53             $self->dispatcher->list_predicates,
54             $self->dispatcher->list_also_predicates,
55             ]);
56             }
57              
58             __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.142820
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