8

Moose is very lovely, but sometimes simple typos can cause hair-raisingly exciting long stacktraces with, from my point of view, zero useful content.

So, are there any tools to interpret this exploding into something helpful?

In particular for classes using plain Moose, Moose+MooseX::Method::Signatures, and MooseX::Declare.

The tools only need to be helpful while developing to catch those typo or thinko problems that make things just not work.

=========================

Following suggestion below, I'm using this not-quite-a-module-yet which is reducing my headaches a little, more ideas welcome, though:

package MooseX::QuietCarping;
# Not actually a Moose thing, but helpful for Moose.
# calm Moose-internal stacktraces down a little
use Carp;

my %retain = ();
sub import {
    my $class = shift;
    $retain{$_}++ for @_;
}

CHECK {
    for (sort keys %INC) {
    s{\.pm$}{};
    s{[/\\]}{::}g; # CROSS PLATFORM MY ARSE
    next if $retain{$_};
    $Carp::Internal{$_}++ if /^(?:Class::MOP|Moose|MooseX)\b/
    }
    %retain = (); # don't need this no more
}

1;
Alex
  • 5,863
  • 2
  • 29
  • 46
  • 1
    Note that the Moose team also relies on community feedback on errors that could be caught. A stacktrace is often much more information than required, but it makes sure it usually isn't too little. A better error message is usually a welcomed feature request. – phaylon May 30 '11 at 16:17
  • 1
    @phaylon You're probably correct, but I'd rather my software was designed for the users than for the authors. – Schwern May 30 '11 at 20:30
  • 1
    I've now found this question along the same lines - seems that this is mostly in the 'wait and see' phase of development: http://stackoverflow.com/questions/4341116/succinct-moosexdeclare-method-signature-validation-errors – Alex May 31 '11 at 04:01

3 Answers3

4

One way I experimented with some time ago is putting Moose related classes into %Carp::Internal hash, something like this:

$Carp::Internal{$_}++ for qw{
    Class::MOP
    Class::MOP::Attribute
    Class::MOP::Class
    ...
};

Such classes will be skipped in stack trace, making it more compact and emphasizing your own code.

You can find them by traversing %INC variable:

package Dummy;
use Moose;
use MooseX::Declare;
# use ....;

for (sort keys %INC) {
    s{\.pm$}{};
    s{/}{::}g;
    print "$_\n" if /^(Class::MOP|Moose|MooseX)\b/;
}
bvr
  • 9,687
  • 22
  • 28
2

I seem to recall seeing a PerlMonks post by stvn a week or two ago saying that they're working on improving the Moose error messages. I don't think there's anything currently available to clean the up, though.

Dave Sherohman
  • 45,363
  • 14
  • 64
  • 102
2

Method::Signatures::Modifiers is a package which hopes to fix some of the problems of MooseX::Method::Signatures. Simply use it to overload.

use MooseX::Declare;
use Method::Signatures::Modifiers;

class Foo
{
    method bar (Int $thing) {
        # this method is declared with Method::Signatures instead of MooseX::Method::Signatures
    }
}
Joel Berger
  • 20,180
  • 5
  • 49
  • 104