| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Lab::Moose::DataFile; |
|
2
|
|
|
|
|
|
|
$Lab::Moose::DataFile::VERSION = '3.900'; |
|
3
|
|
|
|
|
|
|
#ABSTRACT: Base class for data file types |
|
4
|
|
|
|
|
|
|
|
|
5
|
27
|
|
|
27
|
|
16651
|
use v5.20; |
|
|
27
|
|
|
|
|
96
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
27
|
|
|
27
|
|
149
|
use warnings; |
|
|
27
|
|
|
|
|
58
|
|
|
|
27
|
|
|
|
|
733
|
|
|
8
|
27
|
|
|
27
|
|
145
|
use strict; |
|
|
27
|
|
|
|
|
61
|
|
|
|
27
|
|
|
|
|
535
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
27
|
|
|
27
|
|
141
|
use Moose; |
|
|
27
|
|
|
|
|
60
|
|
|
|
27
|
|
|
|
|
168
|
|
|
11
|
27
|
|
|
27
|
|
173986
|
use MooseX::StrictConstructor; |
|
|
27
|
|
|
|
|
77
|
|
|
|
27
|
|
|
|
|
252
|
|
|
12
|
27
|
|
|
27
|
|
87304
|
use MooseX::Params::Validate; |
|
|
27
|
|
|
|
|
75
|
|
|
|
27
|
|
|
|
|
286
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
27
|
|
|
27
|
|
12617
|
use Lab::Moose::DataFolder; |
|
|
27
|
|
|
|
|
68
|
|
|
|
27
|
|
|
|
|
1040
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
27
|
|
|
27
|
|
165
|
use File::Basename qw/dirname basename/; |
|
|
27
|
|
|
|
|
92
|
|
|
|
27
|
|
|
|
|
1762
|
|
|
17
|
27
|
|
|
27
|
|
197
|
use File::Path 'make_path'; |
|
|
27
|
|
|
|
|
68
|
|
|
|
27
|
|
|
|
|
1832
|
|
|
18
|
27
|
|
|
27
|
|
220
|
use Lab::Moose::Catfile 'our_catfile'; |
|
|
27
|
|
|
|
|
80
|
|
|
|
27
|
|
|
|
|
1357
|
|
|
19
|
27
|
|
|
27
|
|
195
|
use IO::Handle; |
|
|
27
|
|
|
|
|
64
|
|
|
|
27
|
|
|
|
|
1139
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
27
|
|
|
27
|
|
13857
|
use Net::RFC3161::Timestamp; |
|
|
27
|
|
|
|
|
1324381
|
|
|
|
27
|
|
|
|
|
1852
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
27
|
|
|
27
|
|
255
|
use Carp; |
|
|
27
|
|
|
|
|
68
|
|
|
|
27
|
|
|
|
|
1493
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
27
|
|
|
27
|
|
187
|
use namespace::autoclean; |
|
|
27
|
|
|
|
|
64
|
|
|
|
27
|
|
|
|
|
273
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has folder => ( |
|
28
|
|
|
|
|
|
|
is => 'ro', |
|
29
|
|
|
|
|
|
|
isa => 'Lab::Moose::DataFolder', |
|
30
|
|
|
|
|
|
|
required => 1, |
|
31
|
|
|
|
|
|
|
); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has filename => ( |
|
34
|
|
|
|
|
|
|
is => 'ro', |
|
35
|
|
|
|
|
|
|
isa => 'Str', |
|
36
|
|
|
|
|
|
|
required => 1, |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has autoflush => ( |
|
40
|
|
|
|
|
|
|
is => 'ro', |
|
41
|
|
|
|
|
|
|
isa => 'Bool', |
|
42
|
|
|
|
|
|
|
default => 1 |
|
43
|
|
|
|
|
|
|
); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has timestamp => ( |
|
46
|
|
|
|
|
|
|
is => 'ro', |
|
47
|
|
|
|
|
|
|
isa => 'Bool', |
|
48
|
|
|
|
|
|
|
default => 0 |
|
49
|
|
|
|
|
|
|
); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has tsauthority => ( |
|
52
|
|
|
|
|
|
|
is => 'ro', |
|
53
|
|
|
|
|
|
|
isa => 'Str', |
|
54
|
|
|
|
|
|
|
default => 'dfn.de' |
|
55
|
|
|
|
|
|
|
); |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
has filehandle => ( |
|
58
|
|
|
|
|
|
|
is => 'ro', |
|
59
|
|
|
|
|
|
|
isa => 'FileHandle', |
|
60
|
|
|
|
|
|
|
writer => '_filehandle', |
|
61
|
|
|
|
|
|
|
init_arg => undef |
|
62
|
|
|
|
|
|
|
); |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
has mode => ( |
|
65
|
|
|
|
|
|
|
is => 'ro', |
|
66
|
|
|
|
|
|
|
isa => 'Str', |
|
67
|
|
|
|
|
|
|
builder => '_build_file_mode', |
|
68
|
|
|
|
|
|
|
); |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _build_file_mode { |
|
71
|
37
|
|
|
37
|
|
1592
|
return '+>'; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# relative to cwd. |
|
75
|
|
|
|
|
|
|
has path => ( |
|
76
|
|
|
|
|
|
|
is => 'ro', |
|
77
|
|
|
|
|
|
|
isa => 'Str', |
|
78
|
|
|
|
|
|
|
writer => '_path', |
|
79
|
|
|
|
|
|
|
init_arg => undef |
|
80
|
|
|
|
|
|
|
); |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub BUILD { |
|
83
|
110
|
|
|
110
|
0
|
4860
|
my $self = shift; |
|
84
|
110
|
|
|
|
|
319
|
$self->_open_file(); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Subclass this to use fancy stuff like IO::Compress |
|
88
|
|
|
|
|
|
|
sub _open_filehandle { |
|
89
|
109
|
|
|
109
|
|
222
|
my $self = shift; |
|
90
|
109
|
|
|
|
|
195
|
my $path = shift; |
|
91
|
|
|
|
|
|
|
|
|
92
|
109
|
50
|
|
|
|
4083
|
open my $fh, $self->mode(), $path |
|
93
|
|
|
|
|
|
|
or croak "cannot open '$path': $!"; |
|
94
|
|
|
|
|
|
|
|
|
95
|
109
|
|
|
|
|
601
|
return $fh; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# Let subclasses add suffixes |
|
99
|
|
|
|
|
|
|
sub _modify_file_path { |
|
100
|
109
|
|
|
109
|
|
183
|
my $self = shift; |
|
101
|
109
|
|
|
|
|
161
|
my $path = shift; |
|
102
|
109
|
|
|
|
|
233
|
return $path; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _open_file { |
|
106
|
110
|
|
|
110
|
|
173
|
my $self = shift; |
|
107
|
|
|
|
|
|
|
|
|
108
|
110
|
|
|
|
|
3333
|
my $folder = $self->folder->path(); |
|
109
|
110
|
|
|
|
|
2961
|
my $filename = $self->filename(); |
|
110
|
|
|
|
|
|
|
|
|
111
|
110
|
|
|
|
|
2938
|
my $dirname = dirname($filename); |
|
112
|
110
|
|
|
|
|
442
|
my $dirpath = our_catfile( $folder, $dirname ); |
|
113
|
|
|
|
|
|
|
|
|
114
|
110
|
100
|
|
|
|
1950
|
if ( not -e $dirpath ) { |
|
115
|
3
|
50
|
|
|
|
474
|
make_path($dirpath) |
|
116
|
|
|
|
|
|
|
or croak "cannot make directory '$dirname'"; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
110
|
|
|
|
|
479
|
my $path = our_catfile( $folder, $filename ); |
|
120
|
|
|
|
|
|
|
|
|
121
|
110
|
|
|
|
|
421
|
$path = $self->_modify_file_path($path); |
|
122
|
|
|
|
|
|
|
|
|
123
|
110
|
|
|
|
|
4278
|
$self->_path($path); |
|
124
|
|
|
|
|
|
|
|
|
125
|
110
|
50
|
|
|
|
2490
|
if ( -e $path ) { |
|
126
|
0
|
|
|
|
|
0
|
croak "path '$path' does already exist"; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
110
|
|
|
|
|
483
|
my $fh = $self->_open_filehandle($path); |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Do not use crlf line endings on ms-w32. |
|
132
|
110
|
50
|
|
|
|
427
|
binmode $fh |
|
133
|
|
|
|
|
|
|
or croak "cannot set binmode for '$path'"; |
|
134
|
|
|
|
|
|
|
|
|
135
|
110
|
50
|
|
|
|
4054
|
if ( $self->autoflush() ) { |
|
136
|
110
|
|
|
|
|
409
|
$fh->autoflush(); |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
110
|
|
|
|
|
8413
|
$self->_filehandle($fh); |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub _close_file { |
|
144
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
|
145
|
0
|
|
|
|
|
0
|
my $fh = $self->filehandle(); |
|
146
|
|
|
|
|
|
|
|
|
147
|
0
|
0
|
|
|
|
0
|
close $fh || croak "cannot close datafile"; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub DEMOLISH { |
|
151
|
37
|
|
|
37
|
0
|
252
|
my $self = shift; |
|
152
|
|
|
|
|
|
|
|
|
153
|
37
|
50
|
|
|
|
1061
|
if ( $self->timestamp() ) { |
|
154
|
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
$self->_close_file(); |
|
156
|
0
|
|
|
|
|
|
attest_file($self->path(), $self->path().".ts", $self->tsauthority()); |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
}; |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
1; |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
__END__ |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=pod |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=encoding UTF-8 |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 NAME |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Lab::Moose::DataFile - Base class for data file types |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 VERSION |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
version 3.900 |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 METHODS |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 new |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
my $datafile = Lab::Moose::DataFile->new( |
|
184
|
|
|
|
|
|
|
folder => $folder, |
|
185
|
|
|
|
|
|
|
filename => 'myfile.dat' |
|
186
|
|
|
|
|
|
|
); |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head3 Attributes |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=over |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item folder (required) |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
A L<Lab::Moose::DataFolder> object. |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item filename (required) |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
filename in the folder. |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item autoflush |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Enable autoflush of the filehandle. On by default. |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item timestamp |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Request RFC3616 compatible timestamps of the measured data |
|
207
|
|
|
|
|
|
|
upon completion, from the timestamp authority specified via |
|
208
|
|
|
|
|
|
|
tsauthority. Off by default. |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
If enabled, an additional file with the suffix .ts containing |
|
211
|
|
|
|
|
|
|
the signed timestamp will be created. |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item tsauthority |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
When timestamps are requested, specify the authority to be |
|
216
|
|
|
|
|
|
|
contacted. The parameter can be a shorthand as, e.g., "dfn.de"; |
|
217
|
|
|
|
|
|
|
see L<Net::RFC3161::Timestamp> for details. If no valid shorthand |
|
218
|
|
|
|
|
|
|
is found, the parameter is interpreted as a RFC3161 URL. |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=item mode |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
C<open> mode. Defaults to ">". |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=back |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head3 Read-only attributes available after creation: |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=over |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item path |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
path relative to the current working directory. |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=item filehandle |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=back |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
This software is copyright (c) 2023 by the Lab::Measurement team; in detail: |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Copyright 2016 Simon Reinhardt |
|
243
|
|
|
|
|
|
|
2017 Andreas K. Huettel, Simon Reinhardt |
|
244
|
|
|
|
|
|
|
2018 Simon Reinhardt |
|
245
|
|
|
|
|
|
|
2020-2021 Andreas K. Huettel |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
249
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=cut |