in reply to Typecasting a scalar to a module

Perl 6 signatures will let you write subroutines that only allow objects that have certain abilities or fulfill certain rolls. Until then you can check for yourself if the object "can" do what you want:

sub func1 { my $var = $_[0]; if (! ref($var) || ! $var->can('do_something1')) { die "Cannot call do_something1 on passed Var ($var); } # But really this check is redundant # because perl will die with a similar error if you # don't check. The check is only useful if you # want to do something other than die. $var->do_something1(); }


my @a=qw(random brilliant braindead); print $a[rand(@a)];