Quiq/Range.pm

filter: Statementstmt 100% 23 / 23 Branchbran 83.3% 5 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 92.5% 37 / 40 CC 6 SCAR 9.7
CC
6
Cov
94%
new
4.0
numbers
3.0
BEGIN
1.0
CRAP 2.6
« Quiq/Net.pm ↑ Summary Quiq/ContentProcessor/File.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Range - Liste von Integern
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =head1 SYNOPSIS
14  
15 use Quiq::Range;
16
17 # Instantiierung
18 my $rng = Quiq::Range->new($spec);
19
20 # Übersetzung in ein Array von Integern
21 my @arr = Quiq::Range->numbers;
22  
23 =head1 DESCRIPTION
24  
25 Ein Objekt der Klasse repräsentiert eine Liste von Integern. Diese wird
26 vom Nutzer spezifiziert als eine Aufzählung von Angaben der Art
27  
28 N einzelner Integer
29 N-M Bereich von Integern
30  
31 die durch Komma getrennt aufgezählt werden können. Beispiele:
32  
33 Spezfikation Array von Integern
34 --------------------- ----------------------------------
35 7 7
36 1-4 1 2 3 4
37 1,2,3,4 1 2 3 4
38 3,5,7-10,16,81-85,101 3 5 7 8 9 10 16 81 82 83 84 85 101
39  
40 =head1 ATTRIBUTES
41  
42 =over 4
43  
44 =item spec => $spec
45  
46 Die Spezifikation, die dem Konstruktur übergeben wurde.
47  
48 =item numberA => \@numbers
49  
50 Die Übersetzung der Spezifikation in ein Array von Integern.
51  
52 =back
53  
54 =cut
55  
56 # -----------------------------------------------------------------------------
57  
58 package Quiq::Range;
59 1 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 1 our $VERSION = '1.240';
66  
67 # -----------------------------------------------------------------------------
68  
69 =head1 METHODS
70  
71 =head2 Klassenmethoden
72  
73 =head3 new() - Konstruktor
74  
75 =head4 Synopsis
76  
77 $rng = $class->new($spec);
78  
79 =head4 Arguments
80  
81 =over 4
82  
83 =item $spec
84  
85 Spezifikation der Integer-Liste in oben beschiebener Syntax.
86  
87 =back
88  
89 =head4 Returns
90  
91 Objekt
92  
93 =head4 Description
94  
95 Instantiiere ein Objekt gemäß Spezifikation $spec und liefere eine
96 Referenz auf dieses Objekt zurück.
97  
98 =cut
99  
100 # -----------------------------------------------------------------------------
101  
102 2 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
103 2 my $class = shift;
104 2 ▶ my $spec = shift // '';
Condition50%1/2
shift() // ""
l!l
20
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
105  
106 2 my @arr;
107 2 for (split /,/,$spec) {
108 6 my ($min,$max) = split /-/;
109 6 ▶ push @arr,$max? ($min..$max): $_;
Branch: 1 branch
BranchTrueFalseTotal
$max ? : 2 4 6
110 }
111  
112 # Objekt instantiieren
113  
114 2 return $class->SUPER::new(
115 spec => $spec,
116 integerA => \@arr,
117 );
118 }
119  
120 # -----------------------------------------------------------------------------
121  
122 =head2 Objektmethoden
123  
124 =head3 numbers() - Nummern des Bereichs
125  
126 =head4 Synopsis
127  
128 @numbers | $numberA = $rng->numbers;
129 @numbers | $numberA = $class->numbers($spec);
130  
131 =head4 Returns
132  
133 Liste von Nummern (Array of Numbers). Im Skalarkontext eine Referenz
134 auf die Liste.
135  
136 =head4 Description
137  
138 Liefere die Liste der Integers. Die Methode kann als Klassen- oder
139 Objektmethode gerufen werden.
140  
141 =cut
142  
143 # -----------------------------------------------------------------------------
144  
145 2 ▶sub numbers {
Subroutine numbers: called CC=3 SCAR=11.1
Pod documented
146 2 ▶ my $self = ref $_[0]? shift: shift->new(shift);
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 1 1 2
147 2 my $arr = $self->{'integerA'};
148 2 ▶ return wantarray? @$arr: $arr;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 0 2
149 }
150  
151 # -----------------------------------------------------------------------------
152  
153 =head1 VERSION
154  
155 1.240
156  
157 =head1 AUTHOR
158  
159 Frank Seitz, L<http://fseitz.de/>
160  
161 =head1 COPYRIGHT
162  
163 Copyright (C) 2026 Frank Seitz
164  
165 =head1 LICENSE
166  
167 This code is free software; you can redistribute it and/or modify
168 it under the same terms as Perl itself.
169  
170 =cut
171  
172 # -----------------------------------------------------------------------------
173  
174 1 1;
175  
176 # eof
« Quiq/Net.pm ↑ Summary Quiq/ContentProcessor/File.pm »