G'day nysus,

"OK, I just learned that when extending non-Moose modules, you should use the MooseX::NonMoose package."

I did this a few years back; these two articles were extremely helpful:

  1. Subclassing Tricky Non-Moose Classes: Don't Do It
  2. Subclassing Tricky Non-Moose Classes: Constructor Problems

I used the information in those blogs to code Anomaly (a personal, unpublished module), which extends Exception::Class::Base. This module is complete and working; it has examples of code that will cover much of what you might need, such as BUILDARGS & FOREIGNBUILDARGS, and uses MooseX::ClassAttribute.

package Anomaly v0.0.1; use 5.12.0; use Moose; use MooseX::ClassAttribute; use MooseX::NonMoose; extends qw(Exception::Class::Base); use namespace::autoclean; class_has generic_description => ( is => q{ro}, isa => q{Str}, default => q{Generic Anomaly}, ); around BUILDARGS => sub { my ($rc_constructor, $proto, @args) = @_; my $class = ref $proto || $proto; if (@args % 2) { push @args, q{message}; } return $class->$rc_constructor(@args); }; sub FOREIGNBUILDARGS { my ($proto, @args) = @_; my $class = ref $proto || $proto; my %wanted = (); if (@args % 2) { $wanted{message} = shift @args; } my %remaining = (@args); my %translation = (msg => q{message}); for my $key ($class->meta->get_attribute_list()) { if (exists $remaining{$key}) { if (exists $translation{$key}) { $wanted{$translation{$key}} = $remaining{$key}; } delete $remaining{$key}; } } if (exists $remaining{error}) { if (! exists $wanted{message}) { $wanted{message} = $remaining{error}; } delete $remaining{error}; } return (%wanted, %remaining); } has description => ( is => q{rw}, isa => q{Str}, default => sub { __PACKAGE__->generic_description() }, ); has detail => ( is => q{ro}, isa => q{Str}, default => q{}, ); has additional_info => ( is => q{ro}, isa => q{ArrayRef[HashRef]}, default => sub { [] }, lazy => 1, required => 0, ); sub add_additional_info { my ($self, $rh_new_info) = @_; my $ra_current_info = $self->additional_info(); push @$ra_current_info, $rh_new_info; $self->additional_info($ra_current_info); return; } no Exception::Class::Base; no MooseX::NonMoose; no MooseX::ClassAttribute; no Moose; __PACKAGE__->meta->make_immutable; 1;

— Ken


In reply to Re^2: Passing arguments to WWW::Mechanize::Firefox constructor with Moose by kcott
in thread Passing arguments to WWW::Mechanize::Firefox constructor with Moose by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.