in reply to Encapsulation and Subroutine redefined warnings
Here is a super-simple OO framework for you.
Processor.pm
package Processor; # constructor in base class only sub new { my $pkg = shift; bless {}, $pkg; } # init, process, finish in subclasses 1;
Processor/SomeSubClass.pm
package Processor::SomeSubClass; @ISA = ( Processor ); sub init { my $self = shift; # do something } # should be called process_line # this one upcases it sub process { my $self = shift; my $line = shift; return uc( $line ); } sub finish { my $self = shift; # do something } 1;
The script that runs it:
#!/usr/bin/perl use Processor; use Processor::SomeSubClass; my $p = Processor::SomeSubClass->new(); $p->init; while (<>) { print $p->process( $_ ); } $p->finish;
I'm not totally sure if this is what you intended - init and finish coming before and after processing all the lines for example - but it should get you going if you havent't done it before.
Note that my examlpe does not store any of the data in the object - again, because its hard to see what problem you are going to be solving.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Encapsulation and Subroutine redefined warnings
by jspeaks (Novice) on Nov 25, 2003 at 16:46 UTC | |
by qq (Hermit) on Nov 25, 2003 at 23:50 UTC |