Single-File Inheritance
- From: Jim Gibson <jimsgibson@xxxxxxxxx>
- Date: Tue, 17 Jan 2012 17:08:50 -0800
I am trying to do the Right Thing and write a data-processing program
using lofty Object-Oriented principles, instead of my usual lazy
procedural ways, but I am having trouble with putting multiple class
packages into one file. I started out using just one file for
convenience while I develop a framework, and then was planning on
splitting the file into separate modules once I got the basics working.
I am trying to read some data files that have the same format in the
first 6 lines, then have different data records in subsequent lines. I
thought I would write a parent class that reads the header lines, then
child classes to read and parse subsequent lines.
Here is the result:
% cat single.pl
#!/usr/local/bin/perl
use strict;
use warnings;
my $file = ConfigFile->new(); # line 5
package DataFile;
sub new
{
my($class) = shift;
my $self = {};
bless $self, $class;
return $self;
}
package ConfigFile;
our @ISA = qw( DataFile );
% perl single.pl
Can't locate object method "new" via package "ConfigFile" at single.pl
line 5.
% perl -v
This is perl, v5.10.1 (*) built for darwin-2level
If I put the packages in separate files, it works (compiles and runs).
I am almost sure that I have done this type of thing before, and I
can't find any documentation that says I can't.
Should I be able to put multiple packages in a single file and use
inheritance for two of those packages?
Thanks.
--
Jim Gibson
.
- Follow-Ups:
- Re: Single-File Inheritance
- From: David Precious
- Re: Single-File Inheritance
- From: Seymour J.
- Re: Single-File Inheritance
- From: xhoster
- Re: Single-File Inheritance
- Prev by Date: Re: Searching Complex Array Values
- Next by Date: Re: Single-File Inheritance
- Previous by thread: When is @_ undefined?
- Next by thread: Re: Single-File Inheritance
- Index(es):
Relevant Pages
|