Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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 (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]
[erix]: that's a good one. I must remember that :P
[stevieb]: I really dislike how perlbrew doesn't list your version of perl if a newer minor version bump has happened. eg: I use 5.24.1, but 5.24.2 is available, hiding my 5.24.1. I may look at this, as I made it display correctly in berrybrew in cases like this
[stevieb]: choroba just gleaned your post about Module::Starter. I use it too, pretty much for every dist I write

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2017-08-18 20:46 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (310 votes). Check out past polls.