Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: My first attempt at inheritance

by shmem (Chancellor)
on May 31, 2013 at 19:02 UTC ( #1036295=note: print w/replies, xml ) Need Help??

in reply to My first attempt at inheritance

The @ISA array does not appear to work as expected.

True. I guess that's because at runtime IO::Dir::pl->new is called before its namespace is set up proper and its @ISA populated. Wrapping that namespace definition into a BEGIN block fixes that.
And you call the method read_pl(), but all you have is read() in IO::Dir::pl.

use strict; use warnings; use autodie; # not Autodie (update) use IO::Dir; my $dh = IO::Dir::pl->new('.'); while (my $file_name = $dh->read_pl()){ print STDOUT "$file_name\n"; } BEGIN { package IO::Dir::pl; use vars '@ISA'; @ISA = ('IO::Dir'); sub read_pl { my $self = shift; warn "Ok We got here.\n"; return undef; } }

Replies are listed 'Best First'.
Re^2: My first attempt at inheritance
by choroba (Bishop) on May 31, 2013 at 19:10 UTC
    Just moving the package definition higher in the file helps. Also, Autodie should probably be autodie.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Of course it does. But maybe throwing in BEGIN and a pair of curlies has a good side effect on the OP.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1036295]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (12)
As of 2018-01-22 14:42 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (233 votes). Check out past polls.