in reply to What About Providing Constructors in Roles?

The constructor you provided does nothing. Things might get more interesting if the constructor had parameters - do you want to use the same parameters for all the classes consuming the role? What about classes based on Moo/Moose where the constructor is provided by the framework with parameters derived from the public non-lazy attributes?

What are you trying to achieve?

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: What About Providing Constructors in Roles?
by karlgoethebier (Abbot) on Dec 21, 2017 at 18:32 UTC
    "The constructor you provided does nothing..."

    Yes and no. At least it returns the blessed ref.

    "...if the constructor had parameters..."

    But it has parameters, doesn't it?

    "...use the same parameters for all the classes consuming the role..."

    No. And yes. Just passing in the hash ref.

    "...classes based on Moo/Moose..."

    This is what i wanted to avoid.

    "...trying to achieve?"

    Nothing. This is just an exercise.

    Basic idea:

    1. Provide a "generic" constructor (first role)
    2. Specify attributes (next role)
    3. Specify accessors/behaviour (class)
    4. Modify attributes/accessors/behaviour (plugin)

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help