File Coverage

blib/lib/Lab/Moose/DataFile/Gnuplot/Compressed.pm
Criterion Covered Total %
statement 38 41 92.6
branch 3 6 50.0
condition n/a
subroutine 12 13 92.3
pod 2 2 100.0
total 55 62 88.7


line stmt bran cond sub pod time code
1             package Lab::Moose::DataFile::Gnuplot::Compressed;
2             $Lab::Moose::DataFile::Gnuplot::Compressed::VERSION = '3.880';
3             #ABSTRACT: Text based data file ('Gnuplot style'), auto-compressed
4              
5 2     2   2422 use v5.20;
  2         16  
6              
7 2     2   34 use warnings;
  2         5  
  2         53  
8 2     2   15 use strict;
  2         12  
  2         45  
9              
10 2     2   14 use Moose;
  2         6  
  2         17  
11 2     2   15951 use File::Basename qw/dirname basename/;
  2         13  
  2         159  
12 2     2   16 use Lab::Moose::Catfile 'our_catfile';
  2         6  
  2         135  
13 2     2   13 use Module::Load;
  2         9  
  2         20  
14 2     2   135 use Carp;
  2         5  
  2         866  
15              
16             extends 'Lab::Moose::DataFile::Gnuplot';
17              
18             has compression => (
19             is => 'ro',
20             isa => 'Str',
21             default => 'Bzip2',
22             );
23              
24              
25             sub _suffix {
26 1     1   8 my %suffixtable=(
27             None => '',
28             Gzip => '.gz',
29             Bzip2 => '.bz2',
30             Lzf => '.lzf',
31             Xz => '.xz'
32             );
33              
34 1         5 my $module = shift;
35 1 50       7 if (defined $suffixtable{$module}) {
36 1         8 return $suffixtable{$module};
37             } else {
38 0         0 croak "Unsupported compression module $module";
39             };
40             }
41              
42             sub _modify_file_path {
43 1     1   6 my $self = shift;
44 1         4 my $path = shift;
45 1         42 return $path . _suffix($self->compression());
46             }
47              
48             sub _open_filehandle {
49 1     1   4 my $self = shift;
50 1         3 my $path = shift;
51              
52 1         3 my $fh;
53              
54 1 50       41 if ($self->compression() eq 'None') {
55              
56 0         0 $fh = super();
57              
58             } else {
59              
60 1         34 my $modulename = "IO::Compress::" . $self->compression();
61 1         7 load $modulename;
62              
63 1 50       9750 $fh = ("IO::Compress::".$self->compression())->new($path)
64             or croak "cannot open '$path': $!";
65              
66             }
67              
68 1         795 return $fh;
69             }
70              
71             sub add_plot {
72 0     0 1   croak("Compressed data files do not (yet) support plots.");
73             }
74              
75       4 1   sub refresh_plots {
76             }
77              
78             1;
79              
80             __END__
81              
82             =pod
83              
84             =encoding UTF-8
85              
86             =head1 NAME
87              
88             Lab::Moose::DataFile::Gnuplot::Compressed - Text based data file ('Gnuplot style'), auto-compressed
89              
90             =head1 VERSION
91              
92             version 3.880
93              
94             =head1 SYNOPSIS
95              
96             use Lab::Moose;
97              
98             my $folder = datafolder();
99              
100             my $file = datafile(
101             type => 'Gnuplot::Compressed',
102             folder => $folder,
103             filename => 'gnuplot-file.dat',
104             columns => [qw/time voltage temp/]
105             );
106              
107             $file->log(time => 1, voltage => 2, temp => 3);
108              
109             =head1 METHODS
110              
111             =head2 new
112              
113             Supports the following attributes in addition to the
114             L<Lab::Moose::DataFile::Gnuplot> requirements:
115              
116             =over
117              
118             =item * compression
119              
120             Compression type; defaults to 'Bzip2', which is also the only value
121             that has been tested so far. The following values are possible:
122              
123             None
124             Gzip
125             Bzip2
126             Lzf
127             Xz
128              
129             Note that (except for None) this requires the corresponding
130             IO::Compress:: modules to be available; only Gzip and Bzip2 are
131             part of core perl.
132              
133             =back
134              
135             This datafile type does not support any plots.
136              
137             =head1 COPYRIGHT AND LICENSE
138              
139             This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
140              
141             Copyright 2018 Andreas K. Huettel, Simon Reinhardt
142             2020 Andreas K. Huettel
143              
144              
145             This is free software; you can redistribute it and/or modify it under
146             the same terms as the Perl 5 programming language system itself.
147              
148             =cut