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
0
votes
2 answers

Perl Moose::Util::TypeConstraints bug ? what is this error about the name has invalid chars?

That has been hours i am tracking a Moose::Util::TypeConstraints exceptions, i don't understand where it gets to check a type and tells me that the name is incorrect. I tracked the error to a reduced example to try to locate the problem, and it just…
Alex F
  • 826
  • 8
  • 18
0
votes
1 answer

How to initialize classes in constructor using Moose

The way I'm doing it is: package 'My::FH'; use Moose; has 'csv' => ( is => 'ro', isa => 'Text::CSV', ); sub store_data { my $self = shift; ... read lines... $self->csv->parse($line); } __PACKAGE__->meta->make_immutable; 1; but when…
a7omiton
  • 1,597
  • 4
  • 34
  • 61
0
votes
1 answer

"Odd number of hash elements" when declaring MooseX::ClassAttribute

On OSX 'Mavericks', this: package FOO; use Moose; use MooseX::ClassAttribute; class_has 'BAR' => ( is => 'rw' ); ... checks clean per 'perl -c': FOO.pm syntax OK ... but gives this error if I run it simply with 'perl FOO.pm': Odd number of…
amp108
  • 432
  • 3
  • 14
0
votes
1 answer

Perl Moose add instance attribute not class attribute

I need to add attribute to Moose class instance. In the code below, when I create instance of the class Child and add attribute "app" to it, I find this attribute also added when I create next instances. What I am doing wrong, again I need the…
daliaessam
  • 1,636
  • 2
  • 21
  • 43
0
votes
2 answers

Currying in Moose

I'm trying to understand better how the Currying in Moose works. I have used the example in the documentation above, but it doesn't look to work as it is. If I call set_user_agent('MyClient'); I get the following error: Cannot delegate…
barbasa
  • 675
  • 4
  • 22
0
votes
1 answer

Perl MooseX::Declare with method attributes MooseX::MethodAttributes

I am trying to use Moose, MooseX::Declare, and MooseX::MethodAttributes to be able to use class and method keywords instead of package and sub and at the same time get the methods attributes, so I need this form of packages and methods: class Moosey…
daliaessam
  • 1,636
  • 2
  • 21
  • 43
0
votes
3 answers

How can I access a method of the consumer class inside a method created at runtime in a method of the parameterized role using Moose with Perl?

I define a method inside a parametrized role that needs to create a new class at run time using Moose::Meta::Class->create and apply that exact parametrized role to it. I am also making a new method for that role using…
xxxxxxx
  • 5,037
  • 6
  • 28
  • 26
0
votes
2 answers

adding new attributes using moose

I recently learned about Moose. When I create a new attribute in a subclass, it seems to somehow override other functions that should be working... use strict; use warnings; ################################### VEHICLE…
mareoraft
  • 3,474
  • 4
  • 26
  • 62
0
votes
1 answer

How could I update a specific element of a 2D array with Moose in Perl 5?

Here is a class I created using Moose and I would like to do the following : update every element of the 2D Array Stack_dG IF and ONLY IF the object is built with a Temperature other than the default one of 37 through the subroutine…
LPmore
  • 45
  • 6
0
votes
1 answer

Automatically generate moose attribute wrapper methods

Is is possible to supply an accessor wrapper for a moose attribute without having to write it every time? Example: * There is an an attribute of type TkRef * It should provide a wrapper for setting the value * The name of the wrapper should be…
capfan
  • 817
  • 10
  • 26
0
votes
1 answer

Changing Attribute values in an immutable class using Moose

I am fairly new to Moose, and have been trying to follow the best practices. I understand that we should try to make classes immutable when we can. My question is, after object construction, can we change the value of a public attribute using a…
0
votes
1 answer

Perl cyclic use modules

I need to know if this practice for using modules fine or not: MyApp.pm package MyApp; use Moose; use MyApp::View; use MyApp::Config; sub view { return MyApp::View->new; } sub config { return MyApp::Config->new; } MyApp/View.pm package…
daliaessam
  • 1,636
  • 2
  • 21
  • 43
0
votes
1 answer

DelegationToAClassWhichIsNotLoaded error with Moose and XML::LibXML

i have a simple test class using Moose, with a XML::LibXML::Document attribute, but get an error when I use this test class. The test class is: package moosetest; use strict; use warnings; use XML::LibXML; use Moose; has dom => ( is => 'rw', isa…
francois
  • 61
  • 2
  • 8
0
votes
1 answer

Modifying attributes of a Moose::Role at runtime

I have a Moose::Role that contains a network client as an attribute: package Widget; use Moose::Role; has 'network_thingy' => ( isa => Maybe[ThingyClient], ); And of course, I have a couple concrete Moose classes which use this role: package…
Mike Monkiewicz
  • 4,481
  • 1
  • 22
  • 19
0
votes
1 answer

Moose attributes - accepting multiple modules with common parent

Need do something like the next (and more): my $val1 = My::Module::Type1->new(...); my $val2 = My::Module::Type2->new(...); my $some = Some->new( val => [$val1, $val2] ); How to define the $val in a Some package (Moose based)? So, package…
clt60
  • 62,119
  • 17
  • 107
  • 194