Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: My first attempt at inheritance

by shmem (Canon)
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; } }
Comment on Re: My first attempt at inheritance
Select or Download Code
Replies are listed 'Best First'.
Re^2: My first attempt at inheritance
by choroba (Chancellor) 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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2016-05-26 07:13 GMT
Find Nodes?
    Voting Booth?