Ask a Question related to PERL Miscellaneous, Design and Development.
-
Michael Budash #1
Re: Newbie OO question
In article <EbkRa.331382$fC.2436421@news.easynews.com>,
"Ed W" <dodgynewsgroups@ewildgoose.demon.co.uk> wrote:
perldoc perltoot> Hi, I do hope this isn't a question asked 50 times a month, but I'm just
> getting to grips with the OO side of perl and struggling top get my head
> round the sheer volume of info. Please feel free to direct me to the man
> pages, but specific sections would be useful
>
> I have an existing class that I would like to derive some methods from (it's
> compress:PPMd for what it's worth). The ->new function actually returns
> something which is not a hash (in fact I think it may be a C++ reference),
> but I haven't managed to get my debugger to tell me what it is. So what I
> think I would like is for my new derived class to use a hash for data
> storage, but somehow NOT to have to overload every existing method.
>
> To abstract this a bit. Imagine a base class which returns a blessed scaler
> (via a class->new method). Later I want to derive a new class from this
> which needs a lot of attribute storage, and hence a scaler is out, but I
> don't want to have to overload all the methods to avoid breaking things.
>
> Can this be done? Or is this what happens anyway, and I just failed to read
> the manual properly....?
>
> Thanks for basic tuition on this
>
> Ed
>
>
it's all you need... that and maybe damian's book!:
[url]http://www.manning.com/Conway/[/url]
--
Michael Budash
Michael Budash Guest
-
Newbie Question: Biz Card Template Question
Hi, I got the Pagemaker PlugIn - I am using one of the templates for Business Cards - the elements appear to be grouped (bound box all around when I... -
A newbie with a newbie question
Good afternoon everyone, My Name is Dusty I am new to this forum and pretty new to Acrobat. I have Acrobat 9 running on an IMAC running 10.5.2 I... -
newbie question,,,
I converted an AVI to FLV in the encoder. The resulsting file only opens a blank flash 8 player. I can't even get it to play within the flash app.... -
Pen Tool Use Question. (Embarrassingly Newbie Question)
I'm currently using Flash MX and whenever I choose the Pen Tool instead of the pen nib with the small "x" beside it that supposed to show up on... -
Newbie question !!
Hi ! What is the different between ?? #!/usr/bin/perl -w and #!/usr/bin/perl I'm newbie, I just start to learn perl -
James E Keenan #2
Re: Newbie OO question
"Ed W" <dodgynewsgroups@ewildgoose.demon.co.uk> wrote in message
news:EbkRa.331382$fC.2436421@news.easynews.com...(it's> Hi, I do hope this isn't a question asked 50 times a month, but I'm just
> getting to grips with the OO side of perl and struggling top get my head
> round the sheer volume of info. Please feel free to direct me to the man
> pages, but specific sections would be useful
>
> I have an existing class that I would like to derive some methods from1. Have you considered using Data::Dumper to analyze the object?> compress:PPMd for what it's worth). The ->new function actually returns
> something which is not a hash (in fact I think it may be a C++ reference),
> but I haven't managed to get my debugger to tell me what it is. So what I
> think I would like is for my new derived class to use a hash for data
> storage, but somehow NOT to have to overload every existing method.
>
2. A look at the Compress::PPMd source code
([url]http://search.cpan.org/author/SALVA/Compress-PPMd-0.08/MANIFEST[/url]) shows that
this module -- considered by itself -- is not actually object-oriented.
Rather, it's a "regular" Perl module which uses Exporter to export its
functions. It uses XSLoader to load the extension written (I think) in C.
The 'new' method is in the XS, not in the Perl. I don't know enough about
this to comment further; perhaps another list-member can tell you more about
XSLoader.
James E Keenan Guest
-
Jay Tilton #3
Re: Newbie OO question
"Ed W" <dodgynewsgroups@ewildgoose.demon.co.uk> wrote:
: I have an existing class that I would like to derive some methods from (it's
: compress:PPMd for what it's worth). The ->new function actually returns
: something which is not a hash (in fact I think it may be a C++ reference),
: but I haven't managed to get my debugger to tell me what it is. So what I
: think I would like is for my new derived class to use a hash for data
: storage,
Subclassing (via @ISA) is out, but an object from your class could
easily have a field for holding a compress:PPMd object.
: but somehow NOT to have to overload every existing method.
Just because it would require a lot of typing? An AUTOLOAD{} method
in your class could do the dirty work of inspecting the compress:PPMd
object's capabilities and creating fresh methods for you.
Jay Tilton Guest
-
Salvador Fandino #4
Re: Newbie OO question
Hi Ed,
"Ed W" <dodgynewsgroups@ewildgoose.demon.co.uk> wrote in message news:<SItRa.362198$fC.2630720@news.easynews.com>.. .>> > perldoc perltoot
> >
> > it's all you need... that and maybe damian's book!:
> >
> > [url]http://www.manning.com/Conway/[/url]
> Thanks, I have read the perltoot page a few times, but it doesn't seem to
> cover what happens if you want to inherit from an object that has, say, a
> scalar as the underlying object storage, but I need somewhere to store some
> extra object variables.
>
> I suspect that there is something clever possible involving closures, but
> since I'm not quite ready for that yet, I was just wondering if there was a
> standard way out of this...
I know three different ways to do what you want:
1 - use a "has-a" relation instead of a "is-a" one.
Compress::PPMd::Compressor and Compress::PPMd::Decompressor have very
few methods so you only need to write a few proxy methods to call
them.
2 - use a hash private to your package indexed by the Compress::PPMd
objects (untested):
package MyPkg;
use Compress::PPMd;
our @ISA=qw(Compress::PPMd::Compressor);
my %data; # here goes your data
sub new {
my $class=shift;
my $this=$class->SUPER::new(@_);
$data{$this}={ foo => 'bar' }
}
# data(...) stores and retrieves your class object properties
# $obj->data('foo') retrieves property 'foo'
# $obj->data('bar', 'doz') sets property 'bar' as 'doz'
sub data {
my $this=shift;
my $key=shift;
if (@_) {
$data{$this}{$key}=$_[0];
}
else {
return $data{$this}{$key}
}
}
sub DESTROY {
my $this=shift;
delete $data{$this}
eval { $this->SUPER::DESTROY(@_) }
}
3 - tell me why you need to extend the package and maybe I will add
that functionality to Compress::PPMd ;-)
Bye,
- Salva.
Salvador Fandino Guest



Reply With Quote

