File Coverage

blib/lib/D64/Disk/Dir/Iterator.pm
Criterion Covered Total %
statement 23 23 100.0
branch 1 2 50.0
condition 2 6 33.3
subroutine 6 6 100.0
pod 1 1 100.0
total 33 38 86.8


line stmt bran cond sub pod time code
1             package D64::Disk::Dir::Iterator;
2              
3             =head1 NAME
4              
5             D64::Disk::Dir::Iterator - Iterating through Commodore (D64/D71/D81) disk image directory entries
6              
7             =head1 SYNOPSIS
8              
9             use D64::Disk::Dir::Iterator;
10              
11             # Create an iterator with a directory object instance:
12             my $iter = D64::Disk::Dir::Iterator->new($d64DiskDirObj);
13              
14             # Perlish style iterator:
15             while (my $entry = $iter->getNext()) {
16             # ...do something with $entry...
17             }
18              
19             # C++-ish style iterator:
20             for (my $iter = D64::Disk::Dir::Iterator->new($d64DiskDirObj); $iter->hasNext(); $iter->next()) {
21             my $entry = $iter->current();
22             # ...do something with $entry...
23             }
24              
25             =head1 DESCRIPTION
26              
27             This package provides an iterative method of accessing individual directory entries available within D64::Disk::Dir object instance based on a simple class for iterating over Perl arrays. See the description of L package for a complete list of available methods and iteration process examples.
28              
29             =head1 METHODS
30              
31             =cut
32              
33 2     2   16356 use bytes;
  2         4  
  2         10  
34 2     2   76 use strict;
  2         5  
  2         37  
35 2     2   10 use warnings;
  2         3  
  2         53  
36              
37 2     2   9 use base qw( Exporter Array::Iterator );
  2         4  
  2         1176  
38             our %EXPORT_TAGS = ();
39             $EXPORT_TAGS{'all'} = [];
40             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
41             our @EXPORT = qw();
42              
43             our $VERSION = '0.05';
44              
45 2     2   2584 use Carp qw/carp croak verbose/;
  2         4  
  2         454  
46              
47             =head2 new
48              
49             Create an iterator with a D64::Disk::Dir object instance:
50              
51             my $iter = D64::Disk::Dir::Iterator->new($d64DiskDirObj);
52              
53             =cut
54              
55             sub new {
56 3     3 1 19 my $this = shift;
57 3         5 my $d64DiskDirObj = shift;
58 3 50 33     26 croak "Not a D64::Disk::Dir object: \"$d64DiskDirObj\"" unless defined $d64DiskDirObj and $d64DiskDirObj->can("_get_dir_entries");
59 3         9 my $entries = $d64DiskDirObj->_get_dir_entries();
60 3   33     23 my $class = ref($this) || $this;
61 3         21 my $self = $class->SUPER::new($entries);
62 3         126 bless $self, $class;
63 3         7 return $self;
64             }
65              
66             =head1 BUGS
67              
68             There are no known bugs at the moment. Please report any bugs or feature requests.
69              
70             =head1 EXPORT
71              
72             None. No method is exported into the caller's namespace either by default or explicitly.
73              
74             =head1 SEE ALSO
75              
76             L, L, L, L
77              
78             =head1 AUTHOR
79              
80             Pawel Krol, Epawelkrol@cpan.orgE.
81              
82             =head1 VERSION
83              
84             Version 0.05 (2023-05-14)
85              
86             =head1 COPYRIGHT AND LICENSE
87              
88             This module is licensed under a slightly modified BSD license, the same terms as Per Olofsson's "diskimage.c" library and L Perl package it is based on, license contents are repeated below.
89              
90             Copyright (c) 2003-2006, Per Olofsson
91             All rights reserved.
92              
93             Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
94              
95             =over
96              
97             =item *
98              
99             Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
100              
101             =item *
102              
103             Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
104              
105             =back
106              
107             THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
108              
109             diskimage.c website: L
110              
111             =cut
112              
113             1;