line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lab::Moose::DataFile; |
2
|
|
|
|
|
|
|
$Lab::Moose::DataFile::VERSION = '3.880'; |
3
|
|
|
|
|
|
|
#ABSTRACT: Base class for data file types |
4
|
|
|
|
|
|
|
|
5
|
27
|
|
|
27
|
|
17659
|
use v5.20; |
|
27
|
|
|
|
|
107
|
|
6
|
|
|
|
|
|
|
|
7
|
27
|
|
|
27
|
|
176
|
use warnings; |
|
27
|
|
|
|
|
65
|
|
|
27
|
|
|
|
|
770
|
|
8
|
27
|
|
|
27
|
|
161
|
use strict; |
|
27
|
|
|
|
|
73
|
|
|
27
|
|
|
|
|
569
|
|
9
|
|
|
|
|
|
|
|
10
|
27
|
|
|
27
|
|
147
|
use Moose; |
|
27
|
|
|
|
|
71
|
|
|
27
|
|
|
|
|
193
|
|
11
|
27
|
|
|
27
|
|
179702
|
use MooseX::StrictConstructor; |
|
27
|
|
|
|
|
83
|
|
|
27
|
|
|
|
|
229
|
|
12
|
27
|
|
|
27
|
|
88180
|
use MooseX::Params::Validate; |
|
27
|
|
|
|
|
80
|
|
|
27
|
|
|
|
|
188
|
|
13
|
|
|
|
|
|
|
|
14
|
27
|
|
|
27
|
|
12763
|
use Lab::Moose::DataFolder; |
|
27
|
|
|
|
|
78
|
|
|
27
|
|
|
|
|
1050
|
|
15
|
|
|
|
|
|
|
|
16
|
27
|
|
|
27
|
|
178
|
use File::Basename qw/dirname basename/; |
|
27
|
|
|
|
|
64
|
|
|
27
|
|
|
|
|
1759
|
|
17
|
27
|
|
|
27
|
|
245
|
use File::Path 'make_path'; |
|
27
|
|
|
|
|
120
|
|
|
27
|
|
|
|
|
1979
|
|
18
|
27
|
|
|
27
|
|
240
|
use Lab::Moose::Catfile 'our_catfile'; |
|
27
|
|
|
|
|
90
|
|
|
27
|
|
|
|
|
1470
|
|
19
|
27
|
|
|
27
|
|
204
|
use IO::Handle; |
|
27
|
|
|
|
|
69
|
|
|
27
|
|
|
|
|
1135
|
|
20
|
|
|
|
|
|
|
|
21
|
27
|
|
|
27
|
|
14661
|
use Net::RFC3161::Timestamp; |
|
27
|
|
|
|
|
1361631
|
|
|
27
|
|
|
|
|
2018
|
|
22
|
|
|
|
|
|
|
|
23
|
27
|
|
|
27
|
|
273
|
use Carp; |
|
27
|
|
|
|
|
85
|
|
|
27
|
|
|
|
|
1511
|
|
24
|
|
|
|
|
|
|
|
25
|
27
|
|
|
27
|
|
213
|
use namespace::autoclean; |
|
27
|
|
|
|
|
71
|
|
|
27
|
|
|
|
|
292
|
|
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
|
|
1669
|
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
|
4490
|
my $self = shift; |
84
|
110
|
|
|
|
|
314
|
$self->_open_file(); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Subclass this to use fancy stuff like IO::Compress |
88
|
|
|
|
|
|
|
sub _open_filehandle { |
89
|
109
|
|
|
109
|
|
214
|
my $self = shift; |
90
|
109
|
|
|
|
|
185
|
my $path = shift; |
91
|
|
|
|
|
|
|
|
92
|
109
|
50
|
|
|
|
4331
|
open my $fh, $self->mode(), $path |
93
|
|
|
|
|
|
|
or croak "cannot open '$path': $!"; |
94
|
|
|
|
|
|
|
|
95
|
109
|
|
|
|
|
701
|
return $fh; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# Let subclasses add suffixes |
99
|
|
|
|
|
|
|
sub _modify_file_path { |
100
|
109
|
|
|
109
|
|
208
|
my $self = shift; |
101
|
109
|
|
|
|
|
175
|
my $path = shift; |
102
|
109
|
|
|
|
|
236
|
return $path; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _open_file { |
106
|
110
|
|
|
110
|
|
231
|
my $self = shift; |
107
|
|
|
|
|
|
|
|
108
|
110
|
|
|
|
|
3354
|
my $folder = $self->folder->path(); |
109
|
110
|
|
|
|
|
2992
|
my $filename = $self->filename(); |
110
|
|
|
|
|
|
|
|
111
|
110
|
|
|
|
|
2932
|
my $dirname = dirname($filename); |
112
|
110
|
|
|
|
|
472
|
my $dirpath = our_catfile( $folder, $dirname ); |
113
|
|
|
|
|
|
|
|
114
|
110
|
100
|
|
|
|
2173
|
if ( not -e $dirpath ) { |
115
|
3
|
50
|
|
|
|
495
|
make_path($dirpath) |
116
|
|
|
|
|
|
|
or croak "cannot make directory '$dirname'"; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
110
|
|
|
|
|
539
|
my $path = our_catfile( $folder, $filename ); |
120
|
|
|
|
|
|
|
|
121
|
110
|
|
|
|
|
439
|
$path = $self->_modify_file_path($path); |
122
|
|
|
|
|
|
|
|
123
|
110
|
|
|
|
|
4354
|
$self->_path($path); |
124
|
|
|
|
|
|
|
|
125
|
110
|
50
|
|
|
|
2921
|
if ( -e $path ) { |
126
|
0
|
|
|
|
|
0
|
croak "path '$path' does already exist"; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
110
|
|
|
|
|
600
|
my $fh = $self->_open_filehandle($path); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Do not use crlf line endings on ms-w32. |
132
|
110
|
50
|
|
|
|
591
|
binmode $fh |
133
|
|
|
|
|
|
|
or croak "cannot set binmode for '$path'"; |
134
|
|
|
|
|
|
|
|
135
|
110
|
50
|
|
|
|
4181
|
if ( $self->autoflush() ) { |
136
|
110
|
|
|
|
|
467
|
$fh->autoflush(); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
110
|
|
|
|
|
8287
|
$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
|
269
|
my $self = shift; |
152
|
|
|
|
|
|
|
|
153
|
37
|
50
|
|
|
|
1092
|
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.880 |
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 |