in reply to Spiffy: How to define the constructor to take parameters

The following seems to be what you want:

package VesrRec; use strict; use warnings; use Spiffy -Base; field 'raw'; sub new() { my ($class, $raw) = @_; my $self = bless {}, $class; $self->raw($raw); return $self; } package main; my $rec = VesrRec->new ('This one'); print $rec->raw ();

Prints:

This one

Perl is environmentally friendly - it saves trees

Replies are listed 'Best First'.
Re^2: Spiffy: How to define the constructor to take parameters
by bwagner (Initiate) on Oct 28, 2007 at 20:59 UTC
    Thank you, Grandfather!

    This solution works nicely.

    Is there a way to use your solution but employing the "spiffy" call to $self->super instead of my $self = bless {}, $class; ?

    This would enable to fill in another superclass in the future without having to adapt the constructor.

    Thank you
    Bernhard

      Did you try just my $self = super; instead of reflexively posting a question?

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
        Thank you, Dragonfly, I was not aware that super was a method that could be called as a free method. However, I could have seen it if more closely reading the docs.

        For the record, here's what I changed about the constructor:

        sub new() { my $raw = pop @_; my $self = super; $self->raw($raw); return $self; }
        Thank you
        Bernhard