GenOO
view release on metacpan or search on metacpan
lib/GenOO/Data/Structure/DoubleHashArray.pm view on Meta::CPAN
# POD documentation - main docs before the code
=head1 NAME
GenOO::Data::Structure::DoubleHashArray - Object for a data structure which corresponds of a 2D hash whose values are references to array
=head1 SYNOPSIS
# To initialize
my $structure = GenOO::Data::Structure::DoubleHashArray->new();
=head1 DESCRIPTION
This class corresponds to a data structure which is a 2D hash whose primary key could be for
example the strand, its secondary key the chromosome and each value an array reference with
objects that consume the L<GenOO::Region> role.
=head1 EXAMPLES
# Add an entry to the structure
$structure->add_entry($primary_key, $secondary_key, $entry);
=cut
# Let the code begin...
package GenOO::Data::Structure::DoubleHashArray;
$GenOO::Data::Structure::DoubleHashArray::VERSION = '1.5.2';
#######################################################################
####################### Load External modules #####################
#######################################################################
use Modern::Perl;
use autodie;
use Moose;
use namespace::autoclean;
#######################################################################
####################### Interface attributes ######################
#######################################################################
has 'sorting_code_block' => (
isa => 'CodeRef',
is => 'ro',
default => sub { sub {return $_[0] <=> $_[1]} }
);
has 'entries_count' => (
traits => ['Counter'],
is => 'ro',
isa => 'Num',
default => 0,
handles => {
_inc_entries_count => 'inc',
_reset_entries_count => 'reset',
},
);
has 'is_sorted' => (
traits => ['Bool'],
is => 'rw',
isa => 'Bool',
default => 0,
handles => {
_set_is_sorted => 'set',
_unset_is_sorted => 'unset',
is_not_sorted => 'not',
},
);
#######################################################################
######################## Private attributes #######################
#######################################################################
has '_structure' => (
traits => ['Hash'],
is => 'ro',
isa => 'HashRef[HashRef[ArrayRef]]',
default => sub { {} },
);
#######################################################################
######################## Interface Methods ########################
#######################################################################
sub foreach_entry_do {
my ($self, $block) = @_;
A: foreach my $primary_key (keys %{$self->_structure}) {
foreach my $secondary_key (keys %{$self->_structure->{$primary_key}}) {
foreach my $entry (@{$self->_structure->{$primary_key}->{$secondary_key}}) {
my $return_code = $block->($entry);
last A if (defined $return_code and $return_code eq 'break_loop');
( run in 0.689 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )