[Melbourne-pm] New module: Number::Phone::AU

Michael G Schwern schwern at pobox.com
Thu Jan 6 21:01:47 PST 2011

On 2011.1.7 2:45 PM, Toby Wintermute wrote:
> On 7 January 2011 13:55, Josh Heumann <melbourne.pm at joshheumann.com> wrote:
>> Howdy, Australian Perlmongers.  After poking around on CPAN, I realised
>> that there were no modules to validate Australian phone numbers.  So now
>> there is!
>> Introducing Number::Phone::AU:
>> http://search.cpan.org/~heumann/Number-Phone-AU-0.02/lib/Number/Phone/AU.pm
> Line 4: use Mouse;
> :(
> I use Moose everywhere, but don't want some random modules using Mouse instead.

I want to answer that in detail, because Mouse gets a lot of crap based on
outdated information.  I've been relying on Mouse extensively for
Test::Builder2 and it continues to amaze me how complete and fast it is.

(After walking over and talking with Toby in person) Toby's rationale here is
that (apologizes for puppeting you, Toby)::

1) Mouse might be less feature complete.

You'd be hard pressed to find a feature which is missing from Mouse at this
point.  And obviously Mouse has all the features needed for Number::Phone::AU.

2) Moose + Mouse consumes more memory then just Moose.

I measure it at about 1.5 megs more memory or just 10% of Moose.  Insignificant.

There's no really compelling reason why some random module, which is a black
box, can't use Mouse.

> How about using Any::Moose, which will use Mouse unless Moose is loaded?

Short version: sure, there's probably no harm.

Long version:

The problem with Any::Moose is now you may get different bugs depending on if
Moose or Mouse is loaded.  Used to be a bigger problem than it is now.

The second problem with Any::Moose is that Mouse is now significantly *faster*
at runtime than Moose.  This is likely the result of Mouse::XS.  Here's my
benchmarks adapting Ovid's from

Testing Perl 5.012002, Moose 1.21, Mouse 0.88
Benchmark: timing 6000000 iterations of hash, manual, moose, mouse...
      hash:  1 wallclock secs ( 2.03 usr +  0.01 sys =  2.04 CPU) @
2941176.47/s (n=6000000)
    manual:  8 wallclock secs ( 8.87 usr +  0.02 sys =  8.89 CPU) @
674915.64/s (n=6000000)
     moose:  8 wallclock secs ( 9.04 usr +  0.01 sys =  9.05 CPU) @
662983.43/s (n=6000000)
     mouse:  2 wallclock secs ( 3.22 usr +  0.01 sys =  3.23 CPU) @
1857585.14/s (n=6000000)

Add an "isa => 'Int'" type check to the Moose/Mouse attributes and the
difference between Moose and Mouse becomes even more clear.

$ perl ~/devel/benches/mouse_vs_moose
Testing Perl 5.012002, Moose 1.21, Mouse 0.88
Benchmark: timing 6000000 iterations of hash, manual, moose, mouse...
      hash:  3 wallclock secs ( 2.15 usr +  0.01 sys =  2.16 CPU) @
2777777.78/s (n=6000000)
    manual: 10 wallclock secs ( 8.83 usr +  0.01 sys =  8.84 CPU) @
678733.03/s (n=6000000)
     moose: 22 wallclock secs (20.87 usr +  0.02 sys = 20.89 CPU) @
287218.76/s (n=6000000)
     mouse:  4 wallclock secs ( 3.13 usr +  0.01 sys =  3.14 CPU) @
1910828.03/s (n=6000000)

Using Mouse is *faster* than a simple Perl accessor.  It's approaching raw
hash access.  Moose with a type check is 10x slower than raw hash access.

So if you want performance, use Mouse use Moose.  This runs directly counter
to Any::Moose.

Mind you, I'm sure you can kill Mouse performance pretty easily, but as it's a
module tailor built to produce the Moose interface (rather than a sugar
wrapper around a generic Meta Object Protocol) I expect it to continue to get

Moose is about the MOP, and flexibility for MooseX and design purity.  Mouse
is just implementing Moose and can optimize like mad.  Both are valid goals.
Both can happily live together in the same project.  Pick which one you need
for your code.

On error resume stupid

More information about the Melbourne-pm mailing list