File Coverage

lib/Wx/Perl/EntryList/Iterator.pm
Criterion Covered Total %
statement 6 16 37.5
branch n/a
condition n/a
subroutine 2 7 28.5
pod 4 4 100.0
total 12 27 44.4


line stmt bran cond sub pod time code
1             package Wx::Perl::EntryList::Iterator;
2              
3             =head1 NAME
4              
5             Wx::Perl::EntryList::Iterator - iterate over Wx::Perl::EntryList
6              
7             =head1 SYNOPSIS
8              
9             my $list = Wx::Perl::EntryList->new;
10             $list->add_entries_at( 0, [ 'a', 'b', 'c', 'd', 'e' ] );
11             my $it = Wx::Perl::EntryList::FwBwIterator->new;
12             $it->attach( $list );
13              
14             # $it will iterate taking into accounts
15             # insertions/deletions/moves on the list
16              
17             =head1 DESCRIPTION
18              
19             Subclasses of C allow the iteration
20             over an entry list to proceed in accord to operations on the list.
21             For example, if the current element if moved, the iteration will
22             continue from the element's new position.
23              
24             =head1 METHODS
25              
26             =cut
27              
28 1     1   36301 use strict;
  1         2  
  1         32  
29 1     1   4 use base qw(Class::Accessor::Fast);
  1         2  
  1         1139  
30              
31             __PACKAGE__->mk_accessors( qw(current list) );
32              
33             =head2 attach
34              
35             $it->attach( $entrylist );
36              
37             Associates the iterator with the given C.
38              
39             =cut
40              
41             sub attach {
42 0     0 1   my( $self, $entrylist ) = @_;
43              
44 0           $self->list( $entrylist );
45 0           $entrylist->add_subscriber( '*', $self, '_list_changed' );
46             }
47              
48             =head2 detach
49              
50             $it->detach;
51              
52             Detaches the iterator for its associated C.
53              
54             =cut
55              
56             sub detach {
57 0     0 1   my( $self ) = @_;
58              
59 0           $self->list->delete_subscriber( '*', $self );
60 0           $self->list( undef );
61             }
62              
63             sub _list_changed {
64 0     0     my( $self, $list, $event, %args ) = @_;
65              
66 0           $list->_fixup_iterator( $self, $event, %args );
67             }
68              
69             =head2 at_start, at_end
70              
71             C returns true when the iterator points to the first element
72             of the list. C returns true when the iterator points to the
73             last element of the list.
74              
75             =cut
76              
77 0     0 1   sub at_start { $_[0]->current == 0 }
78 0     0 1   sub at_end { $_[0]->current >= $_[0]->list->count - 1 }
79              
80             1;