Quiq/LockedContent.pm

filter: Statementstmt 97.5% 39 / 40 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 100% 5 / 5 totaltotal 96.4% 55 / 57 CC 1 SCAR 0.8
CC
1
Cov
98%
file
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Quiq/SoapWsdlServiceCgi/Demo.pm ↑ Summary Quiq/Gd/Component/Grid.pm »
1 # -----------------------------------------------------------------------------
2  
3 =head1 NAME
4  
5 Quiq::LockedContent - Persistenter Dateininhalt mit Lock
6  
7 =head1 BASE CLASS
8  
9 L<Quiq::Object>
10  
11 =head1 SYNOPSIS
12  
13 use Quiq::LockedContent;
14
15 $obj = Quiq::LockedContent->new($file);
16 $data = $obj->read;
17 ...
18 $obj->write($data);
19  
20 =head1 DESCRIPTION
21  
22 Die Klasse realisiert einen persisteten Inhalt mit Exklusiv-Lock.
23 Der Inhalt kann gelesen und geschrieben werden. Die Datei wird
24 gelockt. Der Lock wird bis zur Destrukturierung des Objekts
25 gehalten.
26  
27 =cut
28  
29 # -----------------------------------------------------------------------------
30  
31 package Quiq::LockedContent;
32 1 ▶use base qw/Quiq::Object/;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 1 our $VERSION = '1.240';
39  
40 1 ▶use Quiq::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶use Quiq::FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 # -----------------------------------------------------------------------------
44  
45 =head1 METHODS
46  
47 =head2 Konstruktor/Destruktor
48  
49 =head3 new() - Instantiiere Objekt
50  
51 =head4 Synopsis
52  
53 $obj = Quiq::LockedContent->new($file);
54  
55 =head4 Returns
56  
57 Objekt
58  
59 =cut
60  
61 # -----------------------------------------------------------------------------
62  
63 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
64 1 my $class = shift;
65 1 my $file = Quiq::Path->expandTilde(shift);
66  
67 1 my $fh = Quiq::FileHandle->open('+>>',$file,-lock=>'EX');
68 1 $fh->autoFlush;
69  
70 1 return bless [$file,$fh],$class;
71 }
72  
73 # -----------------------------------------------------------------------------
74  
75 =head3 close() - Destrukturiere Objekt
76  
77 =head4 Synopsis
78  
79 $obj->close;
80  
81 =head4 Alias
82  
83 destroy()
84  
85 =cut
86  
87 # -----------------------------------------------------------------------------
88  
89 1 ▶sub close {
Subroutine close: called CC=1 SCAR=0.0
Pod documented
90 1 $_[0] = undef;
91 }
92  
93 {
94 1 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
95 1 *destroy = \&close;
96 }
97  
98 # -----------------------------------------------------------------------------
99  
100 =head2 Operationen
101  
102 =head3 file() - Dateipfad
103  
104 =head4 Synopsis
105  
106 $file = $ctr->file;
107  
108 =head4 Returns
109  
110 Dateipfad (String)
111  
112 =cut
113  
114 # -----------------------------------------------------------------------------
115  
116 0 ▶sub file {
Subroutine file: not called CC=1 SCAR=6.9
Pod documented
117 0 return shift->[0];
118 }
119  
120 # -----------------------------------------------------------------------------
121  
122 =head3 read() - Lies Daten
123  
124 =head4 Synopsis
125  
126 $data = $obj->read;
127  
128 =head4 Returns
129  
130 String
131  
132 =cut
133  
134 # -----------------------------------------------------------------------------
135  
136 2 ▶sub read {
Subroutine read: called CC=1 SCAR=0.0
Pod documented
137 2 my $self = shift;
138  
139 2 my $fh = $self->[1];
140 2 $fh->seek(0);
141  
142 2 return $fh->slurp;
143 }
144  
145 # -----------------------------------------------------------------------------
146  
147 =head3 write() - Schreibe Daten
148  
149 =head4 Synopsis
150  
151 $obj->write($data);
152  
153 =cut
154  
155 # -----------------------------------------------------------------------------
156  
157 1 ▶sub write {
Subroutine write: called CC=1 SCAR=0.0
Pod documented
158 1 my $self = shift;
159 # @_: $data
160  
161 1 my $fh = $self->[1];
162 1 $fh->truncate;
163 1 $fh->print($_[0]);
164  
165 1 return;
166 }
167  
168 # -----------------------------------------------------------------------------
169  
170 =head1 VERSION
171  
172 1.240
173  
174 =head1 AUTHOR
175  
176 Frank Seitz, L<http://fseitz.de/>
177  
178 =head1 COPYRIGHT
179  
180 Copyright (C) 2026 Frank Seitz
181  
182 =head1 LICENSE
183  
184 This code is free software; you can redistribute it and/or modify
185 it under the same terms as Perl itself.
186  
187 =cut
188  
189 # -----------------------------------------------------------------------------
190  
191 1 1;
192  
193 # eof
« Quiq/SoapWsdlServiceCgi/Demo.pm ↑ Summary Quiq/Gd/Component/Grid.pm »