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

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; } }

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1036295]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2016-10-01 19:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (7 votes). Check out past polls.