Set::Associate::NewKey - New Key assignment methods
version 0.002000
This class implements the mechanism which controls how the values are assigned to 'new' keys.
The part you're mostly interested in are the "CLASS METHODS", which return the right populator.
This is more or less a wrapper for passing around subs with an implict interface.
my $assigner = Set::Associate::NewKey->new( name => 'linear_wrap', code => sub { my ( $self, $sa , $key ) = @_; .... }, ); my $value = $assigner->run( $set_associate_object, $key );
required Str
required CodeRef
shift's the first item off the internal _items_cache
shift
_items_cache
my $sa = Set::Associate->new( ... on_new_key => Set::Associate::NewKey->linear_wrap );
or alternatively
my $code = Set::Associate::NewKey->linear_wrap my $newval = $code->run( $set, $key_which_will_be_ignored );
non-destructively picks an element from _items_cache at random.
my $sa = Set::Associate->new( ... on_new_key => Set::Associate::NewKey->random_pick );
my $code = Set::Associate::NewKey->random_pick my $newval = $code->run( $set, $key_which_will_be_ignored );
Assuming offset is numeric, pick either that number, or a modulo of that number.
NOTE: do not use this unless you are only working with numeric keys.
If you're using anything else, the hash_sha1 or hash_md5 methods are suggested.
my $sa = Set::Associate->new( ... on_new_key => Set::Associate::NewKey->pick_offset );
my $code = Set::Associate::NewKey->pick_offset my $newval = $code->run( $set, 9001 ); # despite picking numbers OVER NINE THOUSAND # will still return items in the array
requires bigint support
Determines the offset for "pick_offset" from taking the numeric value of the SHA1 hash of the given string
my $sa = Set::Associate->new( ... on_new_key => Set::Associate::NewKey->hash_sha1 );
my $code = Set::Associate::NewKey->hash_sha1(); my $newval = $code->run( $set, "Some String" );
Determines the offset for "pick_offset" from taking the numeric value of the MD5 hash of the given string
my $sa = Set::Associate->new( ... on_new_key => Set::Associate::NewKey->hash_md5 );
my $code = Set::Associate::NewKey->hash_md5(); my $newval = $code->run( $set, "Some String" );
runs code attached via "code"
my $value = $object->run( $set_associate_object , $key );
And $value is the newly formed associaiton value.
$value
Kent Fredric <kentfredric@gmail.com>
This software is copyright (c) 2013 by Kent Fredric <kentfredric@gmail.com>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Set::Associate, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Set::Associate
CPAN shell
perl -MCPAN -e shell install Set::Associate
For more information on module installation, please visit the detailed CPAN module installation guide.