Bubblegum

 view release on metacpan or  search on metacpan

lib/Bubblegum/Object/Hash.pm  view on Meta::CPAN

# ABSTRACT: Common Methods for Operating on Hash References
package Bubblegum::Object::Hash;

use 5.10.0;
use namespace::autoclean;

use Bubblegum::Class 'with';
use Bubblegum::Constraints -isas, -types;

with 'Bubblegum::Object::Role::Defined';
with 'Bubblegum::Object::Role::Keyed';
with 'Bubblegum::Object::Role::Ref';
with 'Bubblegum::Object::Role::Coercive';
with 'Bubblegum::Object::Role::Output';

use Clone 'clone';

our @ISA = (); # non-object

our $VERSION = '0.45'; # VERSION

sub aslice {
    goto &array_slice;
}

sub array_slice {
    my $self = CORE::shift;
    my @keys = map { type_string $_ } @_;
    return [@{$self}{@keys}];
}

sub clear {
    goto ∅
}

sub defined {
    my $self = CORE::shift;
    my $key  = type_string CORE::shift;
    return CORE::defined $self->{$key};
}

sub delete {
    my $self = CORE::shift;
    my $key  = type_string CORE::shift;
    return CORE::delete $self->{$key};
}

sub each {
    my $self = CORE::shift;
    my $code = CORE::shift;

    $code = $code->codify if isa_string $code;
    type_coderef $code;

    for my $key (CORE::keys %$self) {
      $code->($key, $self->{$key}, @_);
    }

    return $self;
}

sub each_key {
    my $self = CORE::shift;
    my $code = CORE::shift;



( run in 1.287 second using v1.01-cache-2.11-cpan-0d23b851a93 )