Created
November 6, 2012 20:44
-
-
Save sevvie/4027397 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
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