Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Thursday April 03, 2008
11:23 AM

Find the Bug!

[ #36045 ]

This was fun. Calls to $self->_initialize exposed a nasty bug. There's enough context below for you to see it.

sub _initialize {
    my $self = shift;
    $self->SUPER::_initialize;
    my $description = $self->{description};
    $self->{$_} = [] foreach $self->_can_contain;

    while ( my ( $type, $class ) = each %{ $self->_item_classes } ) {
        my $source = $self->source;
        foreach my $metadata ( @{ $description->{$type} } ) {
            push @{ $self->{$type} } =>
                $class->new_from_metadata( {
                    metadata => $metadata,
                    source   => $source,
                } );
        }
    }
}

sub _item_classes {
    my $self = shift;
    my %class_for = (
        attributes => 'Bermuda::Island::Attribute',
        elements   => 'Bermuda::Island::Element',
    );
    my %item_classes;
    foreach my $type ( $self->_can_contain ) {
        $item_classes{$type} = $class_for{$type};
    }
    return \%item_classes;
}

sub _can_contain { qw/ attributes elements / }

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • sub href {
        my %h = (
            foo => 1,
            bar => 2,
        );
        return \%h;
    }

    while (my ($k, $v) = %{ href() }) {
        print "$k => $v\n";
    }
  • Wow. People usually spot it sooner than this. Looks like I had a bit of stumper on this one. Good work :)