[QUIZ] Perl 'What does this code do?' Quiz
Shlomi Fish <shlomif-ik1l9ssToec+JF/[email protected]> Wed, 27 Jun 2007 22:05:53 +0300
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
Hi all!
Here's another "What does this code do?" Quiz. I obfuscated the names of the
variable names to provide hinting on their purpose, but the code itself is
not obfuscated. You have to guess what the "z()" function does.
Good luck!
Please post spoilers as response to this post with "SPOILER".
Regards,
Shlomi Fish
<<<<<<<<<<<<<<<<<<<<<
use strict;
use warnings;
use List::MoreUtils (qw(uniq));
our %_t = ();
sub t
{
my $c = shift;
if (exists($_t{$c}))
{
return $_t{$c};
}
no strict 'refs';
my @h = $c;
my @d = @{$c. '::ISA'};
while (my $p = shift(@d))
{
push @h, $p;
push @d, @{$p. '::ISA'};
}
my @u = uniq(@h);
return $_t{$c} =
[
sort
{
$a->isa($b) ? -1
: $b->isa($a) ? +1
: 0
}
@u
];
}
sub z
{
my ($self, $args) = @_;
my $mn = $args->{mn};
my $c = ((ref($self) eq "") ? $self : ref($self));
my $h= t($c);
my @r;
foreach my $i (@$h)
{
no strict 'refs';
my $m = ${$i . "::"}{$mn};
if (defined($m))
{
push @r, @{$m->($self)};
}
}
return \@r;
}
>>>>>>>>>>>>>>>>>>>>>
Regards,
Shlomi Fish
---------------------------------------------------------------------
Shlomi Fish shlomif-ik1l9ssToec+JF/[email protected]
Homepage: http://www.shlomifish.org/
If it's not in my E-mail it doesn't happen. And if my E-mail is saying
one thing, and everything else says something else - E-mail will conquer.
-- An Israeli Linuxer