Skip to content

Instantly share code, notes, and snippets.

@sevvie
Created November 6, 2012 20:44
Show Gist options
  • Save sevvie/4027397 to your computer and use it in GitHub Desktop.
Save sevvie/4027397 to your computer and use it in GitHub Desktop.
{
package Card;
sub new {
my $type = shift;
my $obj = [];
my $args = [@_];
if( ref(\$args->[0]) eq 'SCALAR' ) {
if( $args->[0] eq 'key' ) {
$obj = [$args->[1], $args->[3]];
} else {
$obj = [\$args];
}
} elsif( ref($args) eq 'ARRAY' ) {
$obj = [\$args];
} elsif( ref($args) eq 'HASH' ) {
$obj = [ $args->{key}, $args->{value} ]
}
return bless $obj, $type;
}
sub key {
return $_->[0];
}
sub value {
return $_->[1];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment