Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

inheritance and __DATA__

by thpfft (Chaplain)
on Apr 13, 2004 at 00:03 UTC ( [id://344569]=perlquestion: print w/replies, xml ) Need Help??

thpfft has asked for the wisdom of the Perl Monks concerning the following question:

It looks like mixing inheritance and __DATA__ tokens doesn't work too well. The method seems to persist in looking for a data section in the superclass that contains it, rather than the subclasses which have inherited it. Can anyone confirm this, or suggest a workaround which will allow me to use inline data in an inherited method?

(This is for a Class::DBI subclass which creates and repairs its own tables. The repair methods are contained in the usual subclass of cdbi, and the data classes inherit them from there. It's very handy for installations and upgrades, as well as making things generally more robust.

The table creation and repair works nicely, but I've run into trouble trying to make the data classes fill each newly-created table with the right default data. The obvious place to store it would be in the __DATA__ footer of each data class (as CSV, for now), which is where I run into the problem described above.)

thanks.

Replies are listed 'Best First'.
Re: inheritance and __DATA__
by bbfu (Curate) on Apr 13, 2004 at 01:08 UTC

    You need to fully qualify the package in which the DATA section you wish to access resides. One way to do so is given below in the flux sub.

    Update: Summary (click readmore for full test code and output):

    sub flux { my $class = ref shift; my $fh = do { no strict 'refs'; \*{"$class\::DATA"}; }; return "A-flux: " . scalar <$fh>; }

    bbfu
    Black flowers blossom
    Fearless on my breath

      Thank you. Worked very nicely.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://344569]
Approved by kvale
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2024-04-26 02:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found