use Class::Multimethods;

multimethod stringify => (ARRAY) => sub
{
	my @arg = @{$_[0]};
	return "[" .  join(", ",@arg) . "]";
};
multimethod stringify => (HASH) => sub
{
	my %arg = %{$_[0]};
	return "{" . join(", ", map("$_=>$arg{$_}",keys %arg)) . "}";
};
multimethod stringify => (CODE) => sub
{
	return "sub {???}";
};
# and laterÉ

multimethod stringify => ('$') => sub
{
	return qq{"$_[0]"};
};

multimethod stringify => ('#') => sub
{
	return $_[0];
};



$array_or_hash_ref = [5,6,7];

print stringify( [1,2,3] ), "\n";
print stringify( {a=>1,b=>2,c=>3} ), "\n"; 
print stringify( $array_or_hash_ref ), "\n";

print stringify( 2001 ), "\n";
print stringify( "a multiple dispatch oddity" ), "\n";

multimethod stringify => ("*") => sub
{
	return "<<".ref($_[0]).">>";
};

print stringify(\1), "\n";
print stringify(qr/^=head[12]/), "\n";
print stringify(bless {}, CD::Music), "\n";

print stringify( { a=>[1,2,3], b=>{b1=>4,b2=>5}, c=>sub{3} } );

multimethod stringify => (ARRAY) => sub
{
	my @arg = map { stringify($_) } @{$_[0]};
	return "[" .  join(", ",@arg) . "]";
};
multimethod stringify => (HASH) => sub
{
	my %arg = map { stringify($_) } %{$_[0]};
	return "{" . join(", ", map("$_=>$arg{$_}",keys %arg)) . "}";
};

print stringify( { a=>[1,2,3], b=>{b1=>4,b2=>5}, c=>sub{3} } );


#########################################################################
#                                                                       #
#  Copyright (C) 1999 by Manning Publications Co. All Rights Reserved.  #
#                                                                       #
#  This code is free software. It may be used, redistributed            #
#  and/or modified under the terms of the Perl Artistic License         #
#  (see http://www.perl.com/perl/misc/Artistic.html).                   #
#                                                                       #
#########################################################################

