Questions tagged [moose]

Moose is a postmodern object system for Perl 5 that takes the tedium out of writing object-oriented Perl. It borrows all the best features from Perl 6, CLOS (Lisp), Smalltalk, Java, BETA, OCaml, Ruby and more, while still keeping true to its Perl 5 roots.

Moose is an extension of the Perl 5 object system. The main goal of Moose is to make Perl 5 object-oriented programming (OOP) easier, more consistent and less tedious. With Moose you can think more about what you want to do and less about the mechanics of OOP.

Moose links

See Also

sources: moose.perl.org

609 questions
13
votes
6 answers

Moose OOP or Standard Perl?

I'm going into writing some crawlers for a web-site, the idea is that the site will use some back-end Perl scripts to fetch data from other sites, my design (in a very abstract way..) will be to write a package, lets say: package…
snoofkin
  • 8,725
  • 14
  • 49
  • 86
13
votes
1 answer

Why can I use a class name as a Moose type, but not when part of a type union?

I can do this: package Foo; use Moose; has 'time' => ( is => 'rw', isa => 'DateTime' ); package main; use DateTime; my $a = Foo->new(time => DateTime->now); But not this: package Foo; use Moose; has 'time' => ( is => 'rw', …
cubabit
  • 2,527
  • 3
  • 21
  • 34
12
votes
3 answers

Why doesn't "use overload" work with "use namespace:autoclean"?

Ok just to sanity check overload doesnt seem to be working for me. I don't know if it's the version of perl I have, or the version of overload.pm, or something wrong with how I've implemented it, but this code doesnt work for me. perl version This…
qodeninja
  • 10,946
  • 30
  • 98
  • 152
12
votes
1 answer

In Perl/Moose, how can I apply a modifier to a method in all subclasses?

I have a Moose class that is intended to be subclassed, and every subclass has to implement an "execute" method. However, I would like to put apply a method modifier to the execute method in my class, so that it applies to the execute method in all…
Ryan C. Thompson
  • 40,856
  • 28
  • 97
  • 159
12
votes
4 answers

How do you do Design by Contract in Perl?

I'm investigating using DbC in our Perl projects, and I'm trying to find the best way to verify contracts in the source (e.g. checking pre/post conditions, invariants, etc.) Class::Contract was written by Damian Conway and is now maintained by C.…
Adam Bellaire
  • 108,003
  • 19
  • 148
  • 163
12
votes
6 answers

Are MooseX::Declare and MooseX::Method::Signatures production ready?

From the current version (0.98) of the Moose::Manual::MooseX are the lines: We have high hopes for the future of MooseX::Method::Signatures and MooseX::Declare. However, these modules, while used regularly in production by some of the more…
Christopher Bottoms
  • 11,218
  • 8
  • 50
  • 99
12
votes
3 answers

How can I get structured exceptions from Moose?

Consider this simple class: package Foo; use Moose; has foo => ( is => 'rw', isa => 'Int' ); And then this code: use Try::Tiny; use Foo; my $f = try { Foo->new( foo => 'Not an Int' ); } catch { warn $_; }; The code dies with a nice big…
daotoad
  • 26,689
  • 7
  • 59
  • 100
12
votes
2 answers

Perl/Moose OO design, package hierarchy

I'm an average perl programmer. I haven't problem with the language itself, but with the "good" object design. While I'm able understand (most of) CPAN modules, without serious problems, i'm unable design myself even the simple object…
clt60
  • 62,119
  • 17
  • 107
  • 194
12
votes
5 answers

How can I code a factory in Perl and Moose?

Is there a simpler or better (=>easier to maintain) way to use Perl and Moose to instantiate classes based on incoming data? The following code is a stripped down sample from a project I'm working on. package FooBar; use Moose; has 'SUBCLASS'…
lexu
  • 8,766
  • 5
  • 45
  • 63
12
votes
2 answers

What is the best way to create a class attribute in Moose?

I need a class attribute in Moose. Right now I am saying: #!/usr/bin/perl use 5.010; use strict; use warnings; use MooseX::Declare; class User { has id => (isa => "Str", is => 'ro', builder => '_get_id'); has name => (isa =>…
Chas. Owens
  • 64,182
  • 22
  • 135
  • 226
11
votes
1 answer

How to make the Moose constructor die on being passed an undeclared attribute?

Moose is very tolerant by default. You can have a class named Cucumber and pass an undeclared attribute (like wheels) to the constructor. Moose won't complain about that by default. But I might prefer Moose to rather die than accept undeclared…
Lumi
  • 14,775
  • 8
  • 59
  • 92
11
votes
1 answer

Shorthand for referring to Perl/Moose package names?

In both Python and Java we have import to eliminate the repetition of fully-qualified package/module names throughout code. Is there any equivalent in Perl/Moose? I think it would really make Moose nicer to use if we didn't have to repeat…
PBJ
  • 757
  • 8
  • 21
11
votes
3 answers

Is Moose really this slow?

I recently downloaded Moose. Experimentally, I rewrote an existing module in Moose. It seems to be convenient way to avoid writing lots of repetitive code. I ran the tests of the module, and I noticed it was a bit delayed. I profiled the code with…
user181548
11
votes
1 answer

Moops lexical_has and default values

I am trying to understand how lexical_has attributes work in Moops. This feature comes from Lexical::Accessor and, as I understand it, the lexical_has function is able to generate a CODE reference to any attribute a class might "lexically have" by…
G. Cito
  • 6,210
  • 3
  • 29
  • 42
11
votes
2 answers

How can I mock Moose objects?

What strategies have Perl people used when mocking Moose objects that they will inject into other Moose objects as type-constrained attributes? Test::MockObject::Extends doesn't seem to play well with Moose. I need the object to blessed as a…
Jeremy Wall
  • 23,907
  • 5
  • 55
  • 73
1
2
3
40 41