Slash Boxes
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

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Thursday October 26, 2006
05:13 PM

Distractions with Class::BuildMethods

[ #31428 ]

Given that a dear friend of mine is suffering from a personal tragedy which has impacted me quite heavily, I've not been terribly responsive to email lately. If I've ignored you, please don't take it personally.

To distract myself, I've been updating Class::BuildMethods to handle class data. I really didn't want to extend this module, but class data is too important to ignore. If I get more tuits, I'll also make it serializable via Storable, but with the caveat that if there's any state data stored outside of the interface, it won't be able to handle it.

The serialization issue annoys me a bit because I keep getting criticisms that this module doesn't allow one to easily serialize data, but since it was designed to add state data to existing classes regardless of implementation, I didn't think it was important since I could not guarantee that one could serialize all data. However, if all data is set via this module, then the serialization is appropriate.

If I get even more tuits, I'll build a threaded Perl and see if I can make it thread safe. However, I have a friend from the US visiting next week and we're off to Dublin, so no guarantees.

I've also discovered that I rarely use its validation capabilities. Instead, I tend to do this:

package Customer;

use Class::BuildMethods qw/_age/;

sub new { bless $any_reference_you_want, shift }

sub age {
    my $self = shift;
    return $self->_age unless @_;
    my $age = shift;
    die "Too young" if $age < 21;

In the above example, I really should use the validation callback because I'm needlessly duplicating code. But if things are really complicated, I can use this technique of wrapping private methods in a public method to give myself fine-grained control.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I wish the best for your friend, and admire your empathy for them. If humanity has any hope, it lies in such empathy.

    I wonder if your uwillingness to use the validate interface indicates that the interface itself may need some tweaking. Is there a way to install the validator such that it can be more naturally extended if neccessary? (My first thought would be to install it as _age_validate or something, so that you could both call it and extend it, but I'm sure you can think of something more elegant.)