NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Ok, (Score:2)
The construct is quite essential (I personally always use it).
If you use inheritance, the result of not using could be strange since many people would perhaps not understand why their inheritance does not work and errors, which might be quite difficult to debug will occur - I learned to use the
reffunction from this.So some explanation should be added, this explanation is taken from Damian Conway's book [amazon.com] 'Object Oriented Perl', page 172, chapter 6 'Inheritance'.
It's essential to use the two-argument form of
bless. If the PerlHacker class had used the one-argument form.Then the object returned byPerlGuru->new(@args)would have been a PerlHacker object. The one-argument form always blesses into the current package, not the package through which the constructor was called.Another thing is, since all Perl programmers are potential CPAN contributors, some may be experienced, but just not used to the OOP way of doing things - and since inheritance is a really good way of moving improving/extending/patching existing OOP based CPAN modules (as suggested by MJD), removing the construct from core documentation could result in less flexible modules, which will require patches etc. before subclassing can be performed.
I now we are not supposed to put things in our code, which we do not understand, but in my opinion, this case its a bit like
use strict;- do not ask why, just use it - read, evolve - so how can we read and evolve if the examples from the docs are removed? it is not a good idea.Was this kind of the thing you where looking for?
Reply to This
Re:Ok, (Score:2)
The idea is that it's bad to make one constructor both for actually making a new object (class method), as for cloning (object method). Probably nobody ever uses new() as an object method, I'm sure.
Re:Ok, (Score:2)
This has nothing to do with inheritance or the two arg form of bless. It only has to do with being able to call ->new() on an instance of the class, and whether or not that's a good idea.
Most people will never ever do this (as what they really want is a copy constructor, not a "call new on the object" method). I agree that all of these should be removed from the docs forthwith, but not just the docs, I think they should b
Re:Ok, (Score:2)
So this does relate to cloning of objects as bart writes in his comment earlier.
Hmm don't mind me - I just need to do some reading and experimenting...
Re:Ok, (Score:2)
blessand AFAIK I can see I copied something without clearly understanding it - WHOOPS!Well the recommended syntax mentioned in the documentation should perhaps read:
Instead of:
It is custom to buy a kvajebajer in Denmark if you make an obvious mistake like this, so Matts or bart if I meet you some point remind me that I owe you a beer.
:)
And perhaps an excuse to MJD for not paying attention
Re:Ok, (Score:2)
The recommended construct should of course read:Hence the
refand||are the elements, which should be removed.Re:Ok, (Score:2)
No offense, but I think your suggestion of changing it to ref ($class) || $class; actually demonstrates the problem we're trying to solve. Specifically, this is bad:
I would mark that down on a code review because in this case, the line in controversy makes it clear that you expect to be able to pass in either $self or $class. Since you don't know what it is when you call the constructor, having my $class