| 1 | package Lab::Moose::DataFile::Gnuplot::Compressed; | ||||||||||
| 2 | 2 | $Lab::Moose::DataFile::Gnuplot::Compressed::VERSION = '3.881'; | |||||||||
| 3 | #ABSTRACT: Text based data file ('Gnuplot style'), auto-compressed | ||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use v5.20; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use File::Basename qw/dirname basename/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 2 | ▶ | use Lab::Moose::Catfile 'our_catfile'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | ▶ | use Module::Load; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 2 | extends 'Lab::Moose::DataFile::Gnuplot'; | |||||||||
| 17 | |||||||||||
| 18 | 2 | has compression => ( | |||||||||
| 19 | is => 'ro', | ||||||||||
| 20 | isa => 'Str', | ||||||||||
| 21 | default => 'Bzip2', | ||||||||||
| 22 | ); | ||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | sub _suffix { | ||||||||||
| 26 | 1 | ▶ | my %suffixtable=( | ||||||||
|
Subroutine
_suffix: called CC=2 SCAR=7.4
| |||||||||||
| 27 | None => '', | ||||||||||
| 28 | Gzip => '.gz', | ||||||||||
| 29 | Bzip2 => '.bz2', | ||||||||||
| 30 | Lzf => '.lzf', | ||||||||||
| 31 | Xz => '.xz' | ||||||||||
| 32 | ); | ||||||||||
| 33 | |||||||||||
| 34 | 1 | my $module = shift; | |||||||||
| 35 | 1 | ▶ | if (defined $suffixtable{$module}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 1 | return $suffixtable{$module}; | |||||||||
| 37 | } else { | ||||||||||
| 38 | 0 | croak "Unsupported compression module $module"; | |||||||||
| 39 | }; | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | sub _modify_file_path { | ||||||||||
| 43 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_modify_file_path: called CC=1 SCAR=0.0
| |||||||||||
| 44 | 1 | my $path = shift; | |||||||||
| 45 | 1 | return $path . _suffix($self->compression()); | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | sub _open_filehandle { | ||||||||||
| 49 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_open_filehandle: called CC=3 SCAR=11.3
| |||||||||||
| 50 | 1 | my $path = shift; | |||||||||
| 51 | |||||||||||
| 52 | 1 | my $fh; | |||||||||
| 53 | |||||||||||
| 54 | 1 | ▶ | if ($self->compression() eq 'None') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | |||||||||||
| 56 | 0 | $fh = super(); | |||||||||
| 57 | |||||||||||
| 58 | } else { | ||||||||||
| 59 | |||||||||||
| 60 | 1 | my $modulename = "IO::Compress::" . $self->compression(); | |||||||||
| 61 | 1 | load $modulename; | |||||||||
| 62 | |||||||||||
| 63 | 1 | ▶ | $fh = ("IO::Compress::".$self->compression())->new($path) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | or croak "cannot open '$path': $!"; | ||||||||||
| 65 | |||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 1 | return $fh; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | sub add_plot { | ||||||||||
| 72 | 0 | ▶ | croak("Compressed data files do not (yet) support plots."); | ||||||||
|
Subroutine
add_plot: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | ▶ | sub refresh_plots { | |||||||||
|
Subroutine
refresh_plots: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 2 | 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.881 | ||||||||||
| 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 | ||||||||||