| 1 | package BIE::Data::HDF5::File; | ||
| 2 | our $VERSION = '0.01'; | ||
| 3 | 1 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use namespace::autoclean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use v5.10; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 0 | ▶ | use BIE::Data::HDF5 ':all'; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 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__ | ||