Moose/DataFile/Meta.pm

filter: Statementstmt 93.1% 54 / 58 Branchbran 60.0% 6 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 90.0% 72 / 80 SCAR 18.0
CC
6
Cov
88%
log
6.6
BEGIN
1.0
BEGIN
1.0
CRAP 6.1
« Instrument/DummySource.pm ↑ Summary Moose/Instrument/Rigol_DSA815.pm »
1 package Lab::Moose::DataFile::Meta;
2 #ABSTRACT: YAML Metadata file
3 27 $Lab::Moose::DataFile::Meta::VERSION = '3.881';
4 27 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 27 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 27 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 27 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 27 ▶use Time::HiRes qw/gettimeofday tv_interval/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 27 ▶use YAML::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 27 ▶use Fcntl 'SEEK_SET';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 27 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 27 extends 'Lab::Moose::DataFile';
22  
23 27 has mode => (
24 is => 'ro',
25 default => '>>',
26 init_arg => undef
27 );
28  
29 27 has meta_data => (
30 is => 'ro',
31 isa => 'ArrayRef | HashRef',
32 writer => '_meta_data',
33 init_arg => undef
34 );
35  
36 27 has start_time => (
37 is => 'ro',
38 isa => 'ArrayRef[Int]',
39 init_arg => undef,
40 writer => '_start_time'
41 );
42  
43 sub log {
44 75 ▶ my $self = shift;
Subroutine log: called CC=6 SCAR=18.8
Pod documented
45 75 my ($meta)
46 = validated_list( \@_, meta => { isa => 'ArrayRef | HashRef' } );
47  
48 75 my $existing_meta = $self->meta_data();
49 75 ▶ if ( defined $existing_meta ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $existing_meta) { } 2 73 75
50 2 my $meta_type = ref $meta;
51 2 my $existing_meta_type = ref $existing_meta;
52  
53 2 ▶ if ( $meta_type ne $existing_meta_type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta_type ne $existing_meta_type) 0 2 2
54 0 croak "meta has reftype $meta_type "
55 . "while existing meta has reftype $existing_meta_type";
56 }
57  
58 2 ▶ if ( $meta_type eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta_type eq 'ARRAY') { } 0 2 2
59 0 $existing_meta = [ @{$existing_meta}, @{$meta} ];
60 }
61 else {
62 2 $existing_meta = { %{$existing_meta}, %{$meta} };
63 }
64  
65 2 $self->_meta_data($existing_meta);
66 }
67 else {
68 73 $self->_meta_data($meta);
69 }
70  
71 75 my $fh = $self->filehandle();
72  
73 75 ▶ truncate $fh, 0
Branch: 1 branch
BranchTrueFalseTotal
truncate $fh, 0 or croak("truncate failed: $!") 0 75 75
74 or croak "truncate failed: $!";
75 75 ▶ seek $fh, 0, SEEK_SET
Branch: 1 branch
BranchTrueFalseTotal
seek $fh, 0, 0 or croak("seek failed: $!") 0 75 75
76 or croak "seek failed: $!";
77  
78 75 print {$fh} Dump( $self->meta_data );
79 }
80  
81 27 __PACKAGE__->meta->make_immutable();
82  
83  
84 27 1;
85  
86 __END__
87  
88 =pod
89  
90 =encoding UTF-8
91  
92 =head1 NAME
93  
94 Lab::Moose::DataFile::Meta - YAML Metadata file
95  
96 =head1 VERSION
97  
98 version 3.881
99  
100 =head1 SYNOPSIS
101  
102 my $file = Lab::Moose::DataFile::Meta->new(
103 folder => $folder,
104 filename => 'metafile.yml'
105 );
106  
107 $file->log(meta => {key1 => $value1, key2 => $value2});
108  
109 =head1 METHODS
110  
111 =head2 log
112  
113 Log either an hashref or an arrayref to the log file.
114 Augment the file's contents. The new keys/items will be merged with the
115 existing ones. Rewrites the file with the new contents.
116 You may not mixup calls with hashref and arrayref arguments.
117  
118 =head1 COPYRIGHT AND LICENSE
119  
120 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
121  
122 Copyright 2016 Simon Reinhardt
123 2017 Andreas K. Huettel
124 2020 Andreas K. Huettel
125  
126  
127 This is free software; you can redistribute it and/or modify it under
128 the same terms as the Perl 5 programming language system itself.
129  
130 =cut
« Instrument/DummySource.pm ↑ Summary Moose/Instrument/Rigol_DSA815.pm »