Chart-GGPlot
view release on metacpan or search on metacpan
lib/Chart/GGPlot/Params.pm view on Meta::CPAN
method delete ($key) {
delete $self->_hash->{ $self->transform_key($key) };
}
method set ( $key, $value ) {
$self->_hash->{ $self->transform_key($key) } = $value;
}
sub _at {
my ( $self, $key ) = @_;
$self->_hash->{$key};
}
method at ($key) { $self->_at( $self->transform_key($key) ); }
method flatten () {
map { $_ => $self->_at($_) } @{ $self->keys };
}
method hslice ($keys) {
my $class = ref($self);
return bless( { _hash => { map { $_ => $self->at($_) } @$keys } }, $class );
}
*slice = \&hslice;
method kv () {
return [ map { [ $_ => $self->_at($_) ] } @{ $self->keys } ];
}
method merge ($other, $skip_undef=false) {
($other) = Type::Params::validate( [$other],
GGParams->plus_coercions( HashRef, sub { ref($self)->new($_) } ) );
my @other_data = $other->flatten;
if ($skip_undef) {
@other_data = pairgrep { defined $b } @other_data;
}
my $class = ref($self);
return bless( { _hash => { $self->flatten, @other_data } }, $class );
}
method defaults ($other) {
return $self->clone unless defined $other;
return $other->merge( $self, true );
}
method rename ($href_or_coderef) {
my $class = ref($self);
my $new_hash;
if ( Ref::Util::is_coderef($href_or_coderef) ) {
my $f = sub { $href_or_coderef->( $self->transform_key( $_[0] ) ) };
$new_hash = $self->_hash->rename($f);
}
else {
my $mapping = {
pairmap { $self->transform_key($a) => $self->transform_key($b) }
$href_or_coderef->flatten
};
$new_hash = $self->_hash->rename($mapping);
}
return bless( { _hash => $new_hash }, $class );
}
method as_hashref () { $self->_hash; }
method copy () {
return dclone($self);
}
*clone = \©
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Chart::GGPlot::Params - Collection of key-value pairs used in Chart::GGPlot
=head1 VERSION
version 0.002003
=head1 DESCRIPTION
This class provides a duck typing interface similar as
L<Data::Frame::Autobox::HashRef>, and adds a mechanism to its
derived classes to allow customize aliasing of hash keys by overriding
the C<transform_key> classmethod.
=head1 CLASS METHODS
=head2 transform_key
transform_key($key)
Derived classes can override this classmethod to have their own way
of renaming the keys.
=head1 METHODS
=head2 length
length()
( run in 1.113 second using v1.01-cache-2.11-cpan-39bf76dae61 )