| 1 | package TAP::Parser::Iterator; | ||||||||||
| 2 | |||||||||||
| 3 | 38 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 38 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 38 | ▶ | use base 'TAP::Object'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | TAP::Parser::Iterator - Base class for TAP source iterators | ||||||||||
| 11 | |||||||||||
| 12 | =head1 VERSION | ||||||||||
| 13 | |||||||||||
| 14 | Version 3.52 | ||||||||||
| 15 | |||||||||||
| 16 | =cut | ||||||||||
| 17 | |||||||||||
| 18 | 38 | our $VERSION = '3.52'; | |||||||||
| 19 | |||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||
| 21 | |||||||||||
| 22 | # to subclass: | ||||||||||
| 23 | use TAP::Parser::Iterator (); | ||||||||||
| 24 | use base 'TAP::Parser::Iterator'; | ||||||||||
| 25 | sub _initialize { | ||||||||||
| 26 | # see TAP::Object... | ||||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | sub next_raw { ... } | ||||||||||
| 30 | sub wait { ... } | ||||||||||
| 31 | sub exit { ... } | ||||||||||
| 32 | |||||||||||
| 33 | =head1 DESCRIPTION | ||||||||||
| 34 | |||||||||||
| 35 | This is a simple iterator base class that defines L<TAP::Parser>'s iterator | ||||||||||
| 36 | API. Iterators are typically created from L<TAP::Parser::SourceHandler>s. | ||||||||||
| 37 | |||||||||||
| 38 | =head1 METHODS | ||||||||||
| 39 | |||||||||||
| 40 | =head2 Class Methods | ||||||||||
| 41 | |||||||||||
| 42 | =head3 C<new> | ||||||||||
| 43 | |||||||||||
| 44 | Create an iterator. Provided by L<TAP::Object>. | ||||||||||
| 45 | |||||||||||
| 46 | =head2 Instance Methods | ||||||||||
| 47 | |||||||||||
| 48 | =head3 C<next> | ||||||||||
| 49 | |||||||||||
| 50 | while ( my $item = $iter->next ) { ... } | ||||||||||
| 51 | |||||||||||
| 52 | Iterate through it, of course. | ||||||||||
| 53 | |||||||||||
| 54 | =head3 C<next_raw> | ||||||||||
| 55 | |||||||||||
| 56 | B<Note:> this method is abstract and should be overridden. | ||||||||||
| 57 | |||||||||||
| 58 | while ( my $item = $iter->next_raw ) { ... } | ||||||||||
| 59 | |||||||||||
| 60 | Iterate raw input without applying any fixes for quirky input syntax. | ||||||||||
| 61 | |||||||||||
| 62 | =cut | ||||||||||
| 63 | |||||||||||
| 64 | 38 | ▶ | if ( $^O eq 'VMS' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 0 | eval <<'END' ; | |||||||||
| 66 | sub next { | ||||||||||
| 67 | my $self = shift; | ||||||||||
| 68 | my $line = $self->next_raw; | ||||||||||
| 69 | |||||||||||
| 70 | # vms nit: When encountering 'not ok', vms often has the 'not' on a line | ||||||||||
| 71 | # by itself: | ||||||||||
| 72 | # not | ||||||||||
| 73 | # ok 1 - 'I hate VMS' | ||||||||||
| 74 | if ( defined($line) and $line =~ /^\s*not\s*$/ ) { | ||||||||||
| 75 | $line .= ( $self->next_raw || '' ); | ||||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | return $line; | ||||||||||
| 79 | } | ||||||||||
| 80 | END | ||||||||||
| 81 | } | ||||||||||
| 82 | else { | ||||||||||
| 83 | 1672 | ▶ | eval 'sub next { shift->next_raw(@_) }'; | ||||||||
|
Subroutine
next: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | sub next_raw { | ||||||||
|
Subroutine
next_raw: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 87 | 0 | ▶ | require Carp; | ||||||||
|
Subroutine
next_raw: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 88 | 0 | my $msg = Carp::longmess('abstract method called directly!'); | |||||||||
| 89 | 0 | $_[0]->_croak($msg); | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | =head3 C<handle_unicode> | ||||||||||
| 93 | |||||||||||
| 94 | If necessary switch the input stream to handle unicode. This only has | ||||||||||
| 95 | any effect for I/O handle based streams. | ||||||||||
| 96 | |||||||||||
| 97 | The default implementation does nothing. | ||||||||||
| 98 | |||||||||||
| 99 | =cut | ||||||||||
| 100 | |||||||||||
| 101 | 10 | ▶ | sub handle_unicode { } | ||||||||
|
Subroutine
handle_unicode: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 102 | |||||||||||
| 103 | =head3 C<get_select_handles> | ||||||||||
| 104 | |||||||||||
| 105 | Return a list of filehandles that may be used upstream in a select() | ||||||||||
| 106 | call to signal that this Iterator is ready. Iterators that are not | ||||||||||
| 107 | handle-based should return an empty list. | ||||||||||
| 108 | |||||||||||
| 109 | The default implementation does nothing. | ||||||||||
| 110 | |||||||||||
| 111 | =cut | ||||||||||
| 112 | |||||||||||
| 113 | 10 | ▶ | sub get_select_handles { | ||||||||
|
Subroutine
get_select_handles: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 114 | 10 | return; | |||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | =head3 C<wait> | ||||||||||
| 118 | |||||||||||
| 119 | B<Note:> this method is abstract and should be overridden. | ||||||||||
| 120 | |||||||||||
| 121 | my $wait_status = $iter->wait; | ||||||||||
| 122 | |||||||||||
| 123 | Return the C<wait> status for this iterator. | ||||||||||
| 124 | |||||||||||
| 125 | =head3 C<exit> | ||||||||||
| 126 | |||||||||||
| 127 | B<Note:> this method is abstract and should be overridden. | ||||||||||
| 128 | |||||||||||
| 129 | my $wait_status = $iter->exit; | ||||||||||
| 130 | |||||||||||
| 131 | Return the C<exit> status for this iterator. | ||||||||||
| 132 | |||||||||||
| 133 | =cut | ||||||||||
| 134 | |||||||||||
| 135 | #can not call abstract base method, next_raw is a fatal stub | ||||||||||
| 136 | 38 | *exit = *wait = *next_raw; | |||||||||
| 137 | |||||||||||
| 138 | 38 | 1; | |||||||||
| 139 | |||||||||||
| 140 | =head1 SUBCLASSING | ||||||||||
| 141 | |||||||||||
| 142 | Please see L<TAP::Parser/SUBCLASSING> for a subclassing overview. | ||||||||||
| 143 | |||||||||||
| 144 | You must override the abstract methods as noted above. | ||||||||||
| 145 | |||||||||||
| 146 | =head2 Example | ||||||||||
| 147 | |||||||||||
| 148 | L<TAP::Parser::Iterator::Array> is probably the easiest example to follow. | ||||||||||
| 149 | There's not much point repeating it here. | ||||||||||
| 150 | |||||||||||
| 151 | =head1 SEE ALSO | ||||||||||
| 152 | |||||||||||
| 153 | L<TAP::Object>, | ||||||||||
| 154 | L<TAP::Parser>, | ||||||||||
| 155 | L<TAP::Parser::Iterator::Array>, | ||||||||||
| 156 | L<TAP::Parser::Iterator::Stream>, | ||||||||||
| 157 | L<TAP::Parser::Iterator::Process>, | ||||||||||
| 158 | |||||||||||
| 159 | =cut | ||||||||||
| 160 | |||||||||||