File Coverage

blib/lib/BIE/Data/HDF5/File.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package BIE::Data::HDF5::File;
2             our $VERSION = '0.01';
3 1     1   23138 use Moose;
  0            
  0            
4             use namespace::autoclean;
5             use v5.10;
6             use BIE::Data::HDF5 ':all';
7             use BIE::Data::HDF5::Path;
8              
9             has 'h5File' => (
10             is => 'ro',
11             isa => 'Str',
12             required => 1,
13             );
14              
15             has 'fileID' => (
16             is => 'ro',
17             isa => 'Int',
18             writer => 'set_fileID',
19             );
20              
21             # 'loc' always tracks current location
22             has 'loc' => (
23             is => 'rw',
24             isa => 'Str',
25             default => '/',
26             );
27              
28             has 'locID' => (
29             is => 'ro',
30             writer => 'setLoc',
31             isa => 'Int',
32             lazy => 1,
33             default => sub {
34             my $self = shift;
35             H5Gopen($self->fileID, '/');
36             },
37             );
38              
39             around 'loc' => sub {
40             my $orig = shift;
41             my $self = shift;
42             return $self->$orig
43             unless @_;
44              
45             my $p = shift;
46             my $newLocID = H5Gopen($self->locID, $p);
47             if ($newLocID >= 0) {
48             H5Gclose($self->locID);
49             $self->setLoc($newLocID);
50             $self->$orig(h5name($newLocID));
51             }
52             };
53              
54             sub pwd {
55             my $self = shift;
56             BIE::Data::HDF5::Path->new(id => H5Gopen($self->fileID, $self->loc));
57             }
58              
59             sub list {
60             my $self = shift;
61             h5ls($self->locID);
62             }
63              
64             sub cd {
65             my $self = shift;
66             if (@_) {
67             my $p = shift;
68             $self->loc($p);
69             }
70             $self->pwd;
71             }
72              
73             sub BUILD {
74             my $self = shift;
75             if (-e $self->h5File) {
76             $self->set_fileID(H5Fopen($self->h5File));
77             } else {
78             $self->set_fileID(H5Fcreate($self->h5File));
79             }
80             }
81              
82             sub DEMOLISH {
83             my $self = shift;
84             H5Gclose($self->locID);
85             H5Fclose($self->fileID);
86             }
87              
88             __PACKAGE__->meta->make_immutable;
89              
90             1;
91             __END__
92              
93             =head1 NAME
94              
95             BIE::Data::HDF5::File - Perl extension for blah with HDF5 file.
96              
97             =head1 SYNOPSIS
98              
99             use BIE::Data::HDF5::File;
100             my $h5 = BIE::Data::HDF5::File->new(h5File => $HDF5file);
101              
102             =head1 DESCRIPTION
103              
104             BIE::Data::HDF5::File is a module for dealing with HDF5 file written with great help from Moose.
105              
106             =head2 ATTRIBUTES AND METHODS
107              
108             =over
109              
110             =item *
111              
112             "h5File": The required argument for constructing a new BIE::Data::HDF5::File object.
113              
114             =item *
115              
116             "loc": Always return current location in HDF5 data file.
117              
118             =item *
119              
120             "pwd": Return a BIE::Data::HDF5::Path object for more path related operations.
121              
122             =item *
123              
124             "list": Return the list of all entries under current path in HDF5 data file.
125              
126             =item *
127              
128             "cd": Enter a new location in HDF5 data file.
129              
130             =back
131              
132             =head1 SEE ALSO
133              
134             L<BIE::Data::HDF5::Path>
135              
136             L<BIE::Data::HDF5::Data>
137              
138             L<BIE::App::PacBio> See this module for a live example.
139              
140             =head1 AUTHOR
141              
142             Xin Zheng, E<lt>xin@E<gt>
143              
144             =head1 COPYRIGHT AND LICENSE
145              
146             Copyright (C) 2012 by Xin Zheng
147              
148             This library is free software; you can redistribute it and/or modify
149             it under the same terms as Perl itself, either Perl version 5.14.2 or,
150             at your option, any later version of Perl 5 you may have available.
151              
152              
153             =cut