Quiq/DirHandle.pm

filter: Statementstmt 91.3% 21 / 23 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 89.1% 33 / 37 CC 3 SCAR 4.0
CC
3
Cov
85%
new
2.1
close
2.1
BEGIN
1.0
CRAP 1.5
« Quiq/TempDir.pm ↑ Summary Quiq/TableRow.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::DirHandle - Verzeichnis-Handle
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Object>
12  
13 =head1 SYNOPSIS
14  
15 use Quiq::DirHandle;
16
17 my $dh = Quiq::DirHandle->new($dir);
18 while (my $e = $dh->next) {
19 if ($e eq '.' || $e eq '..') {
20 next;
21 }
22 say $e;
23 }
24 $dh->close;
25  
26 =head1 DESCRIPTION
27  
28 Die Klasse stellt eine objektorientierte Schnittstelle zu
29 Perls Directory Handles her. Mit den Methoden der Klasse kann
30 ein Verzeichnis geöffnet und über seine Einträge iteriert werden.
31 Die Standard-Einträge . und .. werden nicht ausgelassen. Diese
32 müssen ggf. selbst übergangen werden.
33  
34 =cut
35  
36 # -----------------------------------------------------------------------------
37  
38 package Quiq::DirHandle;
39 270 ▶use base qw/Quiq::Object/;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 270 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 270 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 270 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 270 our $VERSION = '1.240';
46  
47 # -----------------------------------------------------------------------------
48  
49 =head1 METHODS
50  
51 =head2 Konstruktor/Destruktor
52  
53 =head3 new() - Instantiiere Directory-Handle
54  
55 =head4 Synopsis
56  
57 $dh = $class->new($dir);
58  
59 =head4 Description
60  
61 Instantiiere ein Dirhandle-Objekt für Verzeichnis $dir und liefere
62 eine Referenz auf dieses Objekt zurück.
63  
64 =cut
65  
66 # -----------------------------------------------------------------------------
67  
68 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.6
Pod documented
69 1 my ($class,$dir) = @_;
70  
71 1 ▶ opendir my $dh,$dir or do {
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or do { $class->throw("DIR-00001: Can't open directory", "Dir", $dir, "Error", "$!") } 1 0 1
72 0 $class->throw(
73 'DIR-00001: Can\'t open directory',
74 Dir => $dir,
75 Error => "$!",
76 );
77 };
78  
79 1 return bless $dh,$class;
80 }
81  
82 # -----------------------------------------------------------------------------
83  
84 =head3 close() - Schließe Verzeichnis
85  
86 =head4 Synopsis
87  
88 $dh->close;
89  
90 =head4 Description
91  
92 Schließe das Verzeichnis. Die Methode liefert keinen Wert zurück.
93  
94 =cut
95  
96 # -----------------------------------------------------------------------------
97  
98 1 ▶sub close {
Subroutine close: called CC=2 SCAR=7.4
Pod documented
99 1 my ($self) = @_;
100  
101 1 ▶ closedir $self or do {
Branch: 1 branch
BranchTrueFalseTotal
closedir $self or do { $self->throw("DIR-00002: Failed to close dirhandle", "Error", "$!") } 1 0 1
102 0 $self->throw(
103 'DIR-00002: Failed to close dirhandle',
104 Error => "$!",
105 );
106 };
107  
108 1 $_[0] = undef;
109  
110 1 return;
111 }
112  
113 # -----------------------------------------------------------------------------
114  
115 =head2 Operationen
116  
117 =head3 next() - Liefere nächsten Verzeichniseintrag
118  
119 =head4 Synopsis
120  
121 $entry = $dh->next;
122  
123 =head4 Description
124  
125 Liefere den nächsten Verzeichniseintrag. Die Einträge werden in
126 der Reihenfolge geliefert, wie sie im Verzeichnis stehen, also
127 de facto ungeordnet. Ist das Ende erreicht, liefere undef.
128  
129 =cut
130  
131 # -----------------------------------------------------------------------------
132  
133 8 ▶sub next {
Subroutine next: called CC=1 SCAR=0.0
Pod documented
134 8 return readdir shift;
135 }
136  
137 # -----------------------------------------------------------------------------
138  
139 =head1 VERSION
140  
141 1.240
142  
143 =head1 AUTHOR
144  
145 Frank Seitz, L<http://fseitz.de/>
146  
147 =head1 COPYRIGHT
148  
149 Copyright (C) 2026 Frank Seitz
150  
151 =head1 LICENSE
152  
153 This code is free software; you can redistribute it and/or modify
154 it under the same terms as Perl itself.
155  
156 =cut
157  
158 # -----------------------------------------------------------------------------
159  
160 270 1;
161  
162 # eof
« Quiq/TempDir.pm ↑ Summary Quiq/TableRow.pm »