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
1
vote
2 answers

How to write a Moose base class for roles with inheritable data?

I have a small (soon to be large) set of Moose roles that interact with a database. They have methods like create_foo_record, update_foo_record, delete_foo_record, etc. (They aren't simple wrapper for database access, as they do things like…
Rob
  • 781
  • 5
  • 19
1
vote
1 answer

Who's calling with Moose?

I am trying to write a logger role (with Log::Dispatchouli, but that shouldn't matter) that tells me from which package, sub, line etc. I have been issuing log messages. Naturally, I tried with caller, but stack is full of Moose classes and the…
mokko
  • 186
  • 9
1
vote
1 answer

Setting MooseX::Method::Signatures defaults to an instance variable

I have a set of methods where I would like the caller to be able to override a value, or it defaults to the instance variable. So what I keep trying to do is: method foo( Str :$blah = $self->blah ) { #doStuff } which throws a parsing error so I…
Matt
  • 68,711
  • 7
  • 155
  • 158
1
vote
1 answer

Validation Failing for Valid Hashref

I'm deploying my software (first time in a new environment) and hitting a wall almost immediately. I have a value that is failing its HashRef validation, but every test I can think of makes it seem like it should be valid. Attribute (store) does…
Ryan
  • 672
  • 1
  • 6
  • 16
1
vote
1 answer

Moose Role Derivation

I would like to now what is the better pattern to do what I need. I try to reduce the problem to a minimum, let me explain it step by step. I have an interface Role like: { package Likeable; use Moose::Role; requires 'likers'; …
oleber
  • 1,089
  • 4
  • 12
  • 25
1
vote
1 answer

Can $self be passed to a XML::Twig handler?

I'm trying to parse different XML that is returned depending on the command given in a class method... but I think I'm getting a bit deep here. I'd like to be able to use other methods and access attributes of the instance from WITHIN the XML::Twig…
Chris Matta
  • 3,263
  • 3
  • 35
  • 48
1
vote
2 answers

perl class to parse specified csv file types of similar data with different columns

I'm trying to write a Moose class that parses csv files of slightly different formats with headers and return a list of objects representing the data in the files. Here's a simplified version of the code: package MyParser; use Moose; use…
1
vote
0 answers

Storing Moose attributes in blessed arrayref, for compact storage?

{Moose,Mouse,Moo} object normally translates to a blessed hashref. Can it use blessed arrayref instead, for compact storage? Think an object like bless({long_attribute_name=>1, another_long_attribute_name=>2, and_a_bunch_of_these=>3}, 'SomeClass')…
Steven Haryanto
  • 741
  • 5
  • 13
1
vote
0 answers

BUILD Problems: Connect class chat

I'm having problems with the BUILD method, I want to connect to an HTML-based chat. I wish this class would keep me logged in order to execute the action of sending and receiving messages. I tried the way down, but it seems that causes a stress on…
1
vote
3 answers

Is there a way to use an object's attribute directly in a Perl regex replacement?

I've got a Perl Moose object that contains an attribute I'd like to use as a replacement string in a regex. The idea is to use something like: $full_string =~ s{FIND_THIS}{$self->replace_string}; Where $self->replace_string is the Moose object's…
Alan W. Smith
  • 24,647
  • 4
  • 70
  • 96
1
vote
1 answer

How can I delegate to a sub object of an object with Moose handles?

The Moose documentation says that I can delegate to the object thing easily enough. has 'thing' => ( ... handles => { set_foo => [ set => 'foo' ] }, ); # $self->set_foo(...) calls $self->thing->set('foo', ...) But I really want to delegate…
xenoterracide
  • 16,274
  • 24
  • 118
  • 243
1
vote
1 answer

Can I use an attribute modifer in Moose in a base class to handle multiple attributes from sub classes?

I've got several Modules that have a number of date time related attributes that accept a datestamp and return a human readable string ( dd Mon yyyy hh:mm:ss ). package ModuleOne; use Moose; extends 'ModuleBase'; has date_attr_one => ( ...…
jmcneirney
  • 1,374
  • 8
  • 23
1
vote
3 answers

Make a method uninheritable?

While refactoring I'm trying to retain some backwards compatibility for a time. I'm wondering if it's possible to have a method on an object, but prevent that method from being inherited by classes that subclass it? e.g. given package Class { …
xenoterracide
  • 16,274
  • 24
  • 118
  • 243
0
votes
1 answer

default/replacable values in Bread::Board

I found myself instantiating the same objects in numerous tests, so I'm trying to replace this constant setup by using Bread::Board. Most of the time I will want the dependencies to have the same configuration. But occasionally I may want to have an…
xenoterracide
  • 16,274
  • 24
  • 118
  • 243
0
votes
2 answers

Perl Moose Hash traits

I have a parameter object in Moose which has attributes of file wildcards to glob So I had a method to do this sub getInputFileParams{ my ($self) = @_; #the only parameters passed in are in fact the input files return…
KeepCalmAndCarryOn
  • 8,817
  • 2
  • 32
  • 47