Quiq/Hash/Persistent.pm

filter: Statementstmt 100% 21 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 100% 29 / 29 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Quiq/Gd/Image.pm ↑ Summary Quiq/Html/Base.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Hash::Persistent - Persistente Hash-Datenstruktur
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =head1 DESCRIPTION
14  
15 Definition des Konstruktors in einer abgeleiteten Klasse (in diesem
16 Fall ohne Konstruktorargumente):
17  
18 package MyClass;
19 use base qw/Quiq::Hash::Persistent/;
20
21 sub new {
22 my $class = shift;
23 ...
24 return $class->SUPER::new($file,$timeout,sub {
25 my $class = shift;
26 ...
27 return $class->Quiq::Hash::new(
28 ...
29 );
30 };
31 }
32  
33 =over 2
34  
35 =item *
36  
37 Die Klasse (hier MyClass) wird von Quiq::Hash::Persistent abgeleitet
38  
39 =item *
40  
41 Der Konstruktor der Klasse kann eine beliebige Signatur haben
42  
43 =item *
44  
45 Aus den aktuellen Parametern ergibt sich u.U. der Cache-Dateiname
46  
47 =item *
48  
49 Der gesamte oder zumindest der "teure" Anteil des Konstruktors
50 wird in der anonymen Subroutine sub{} imlementiert
51  
52 =item *
53  
54 Die anonyme Subroutine liefert einen Hash der Klasse Quiq::Hash
55  
56 =back
57  
58 =cut
59  
60 # -----------------------------------------------------------------------------
61  
62 package Quiq::Hash::Persistent;
63 1 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 1 our $VERSION = '1.240';
70  
71 1 ▶use Quiq::Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 # -----------------------------------------------------------------------------
74  
75 =head1 METHODS
76  
77 =head2 Klassenmethoden
78  
79 =head3 new() - Konstruktor
80  
81 =head4 Synopsis
82  
83 $h = $class->new($file,$timeout,$sub);
84  
85 =head4 Arguments
86  
87 =over 4
88  
89 =item $file
90  
91 Cachedatei, in der die Hash.Datenstruktur persistent gespeichert wird.
92  
93 =item $timeout (Integer oder undef)
94  
95 Dauer in Sekunden, die die Cachdatei gültig ist. Falls C<undef>,
96 ist die Cachdatei unbegrenzt lange gültig.
97  
98 =item $sub
99  
100 Subroutine, die den zu persistierenden Hash instantiiert.
101  
102 =back
103  
104 =head4 Returns
105  
106 Referenz auf Hash-Objekt.
107  
108 =head4 Description
109  
110 Instantiiere einen Hash aus Datei $file und liefere eine Referenz
111 auf dieses Objekt zurück. Existiert Datei $file nicht oder liegt
112 ihr letzter Änderungszeitpunkt mehr als abs($timeout) Sekunden
113 zurück, rufe $sub auf, um den Hash zu erzeugen und speichere ihn
114 persistent in Datei $file. Der Hash wird um die Komponenten
115  
116 =over 2
117  
118 =item *
119  
120 cacheFile
121  
122 =item *
123  
124 cacheTimeout
125  
126 =back
127  
128 erweitert.
129  
130 =cut
131  
132 # -----------------------------------------------------------------------------
133  
134 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
135 2 my ($class,$file,$timeout,$sub) = @_;
136  
137 1 ▶ return Quiq::Storable->memoize($file,$timeout,sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
138 1 my $h = $sub->($class);
139 1 $h->add(
140 cacheFile => $file,
141 cacheTimeout => $timeout,
142 );
143 1 return $h;
144 2 });
145 }
146  
147 # -----------------------------------------------------------------------------
148  
149 =head2 Objektmethoden
150  
151 =head3 cacheFile() - Pfad der Cachedatei
152  
153 =head4 Synopsis
154  
155 $file = $self->cacheFile;
156  
157 =head4 Returns
158  
159 Pfad (String)
160  
161 =head4 Description
162  
163 Liefere den Pfad der Cachedatei.
164  
165 =head3 cacheTimeout() - Cache-Timeout
166  
167 =head4 Synopsis
168  
169 $timeout = $self->cacheTimeout;
170  
171 =head4 Returns
172  
173 Anzahl Sekunden (Integer oder undef)
174  
175 =head4 Description
176  
177 Liefere das für die Cachedatei definierte Timeout.
178  
179 =head1 VERSION
180  
181 1.240
182  
183 =head1 AUTHOR
184  
185 Frank Seitz, L<http://fseitz.de/>
186  
187 =head1 COPYRIGHT
188  
189 Copyright (C) 2026 Frank Seitz
190  
191 =head1 LICENSE
192  
193 This code is free software; you can redistribute it and/or modify
194 it under the same terms as Perl itself.
195  
196 =cut
197  
198 # -----------------------------------------------------------------------------
199  
200 1 1;
201  
202 # eof
« Quiq/Gd/Image.pm ↑ Summary Quiq/Html/Base.pm »