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
1 answer

How can I construct a moose object from a hash generated from one of the attributes?

I have a couple of packages: package FOO; use Moose; has 'obj' => (is=>'ro'); sub hash { my $self = shift; return $self->make_hash($self->obj}; } and another package extending FOO: package FOOBAR; use Moose; extends 'FOO'; has [qw/val1…
simon_
  • 43
  • 5
0
votes
2 answers

Moose traits on type unions

In Moose v1.x, I used to be able to do this: package Class; use Test::More tests => 1; use Moose; use MooseX::Types::Moose qw/Undef Str/; eval { has 'trait_boom' => ( is => 'rw' , isa => Str | Undef , default => '' , traits =>…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
0
votes
2 answers

Is there a way to enforce dependencies between MooseX::Traits plugins at object creation time?

Let's say I have a class Foo with plugin traits/roles Bar and Baz, where Baz is dependent on Bar. package Foo; use Moose; with 'MooseX::Traits'; sub foo {print "foo\n"} package Bar; use Moose::Role; sub bar { shift->foo; print…
stevenl
  • 6,736
  • 26
  • 33
0
votes
1 answer

Migrating from Moose to Mouse in Perl - Mouse not executing BUILD

I'm trying to migrate from Moose to Mouse in the interests of speed but have encountered a showstopper error. I'm building two objects in the same scope: sub scope { my $foo = Foo->new(); my $bar = Bar->new(); } The BUILD method of Foo is…
git-noob
  • 5,757
  • 11
  • 34
  • 32
0
votes
1 answer

Is there a Perl/Moose wrapper for Tk

Have you seen a Perl/Moose wrapper for Tk. Or other suggestions how to cleanly build/code a GUI with Perl!
lexu
  • 8,766
  • 5
  • 45
  • 63
0
votes
2 answers

how to call another subroutine after the return statement

How can I call another subroutine from existing subroutine just after the return statement in perl. I dont want to call before the return statement as it is taking time to render. I do not want to wait. return it and then call another subroutine…
Dumb
  • 83
  • 1
  • 10
0
votes
1 answer

Moose Variable names may not contain :: at

So I hit this weird error. Variable names may not contain :: at .../perl5/lib/perl5/x86_64-cygwin-threads-multi/Class/MOP/Package.pm The code that triggers it is: override 'emitEvent::ENOTE::Final' => sub { my ($self, $e) = @_; my…
Erik Bennett
  • 1,049
  • 6
  • 15
0
votes
1 answer

Can I know which child class am I from parent's code in Moose?

I am creating a set of small Perl programs which will be run like a CLI. I want all of them to share some features, eg. same input/output format (probably JSON). I also want each component to be black-box testable with mock arguments. This is what I…
willyjoker
  • 787
  • 6
  • 16
0
votes
1 answer

Read only attributes being filled without writer method in Moose

I'm using Moose to create an object oriented class in Perl. I have a number of attributes which I want to be read only which I've declared like this: package BioIO::SeqIO; use Moose; use namespace::autoclean; use MooseX::StrictConstructor; use…
J0HN_TIT0R
  • 323
  • 1
  • 13
0
votes
1 answer

Getting error for reader and writer accessor method of Moose in perl

I'm trying to use Moose reader and writer for setting and getting a value. The following is employee.pm: package employee; use Moose; has 'firstName' => (is => 'ro' , isa => 'Str' , required => 1); has 'salary' => (is => 'rw', isa =>…
kart1657
  • 78
  • 8
0
votes
1 answer

using List::Compare on an array of Moose Objects

this question succeeds the following question: Moose: Array of Objects->loop through Attribute I'm struggling to implement the grep syntax into a List::Compare Object: my @aIdentList=("z003","t302","p032"); my…
airborne
  • 3,664
  • 4
  • 15
  • 27
0
votes
1 answer

roles and code readability

The improvement of using roles (Moo::Role or Role::Tiny or whatever) with qw( Some::Role Some::Other::Role ); ... some_roles_method(); over just explicitly importing the function from the mixin class use Some::Role…
Kevin G.
  • 1,424
  • 1
  • 13
  • 22
0
votes
1 answer

Perl: Recursive object instantiation with Moose

In the example code below, I am defining a class Person that can have child objects of the same class. When I invoke the printTree method, I am expecting the following output Sam Ram Geeta What I see instead…
vijayvithal
  • 551
  • 1
  • 5
  • 13
0
votes
1 answer

How can I cast an existing Moose object into an extending instance?

I have a Moose class named 'Child' which extends another class named 'Person'. Given a 'Person' instance I would like to create a Child instance. How can I cast the existing 'Person' into a 'Child', without explicitly creating a new Child and…
David B
  • 29,258
  • 50
  • 133
  • 186
0
votes
2 answers

How to set ro attributes during build?

I'm writing a script to help me get proficient in Moose. I've got the following bit of code: package Dir; use Moose; use Modern::Perl; use File; has 'dirs' => (is => 'ro', isa => 'HashRef[Dir]' ); has 'files' => (is =>…
StevieD
  • 6,925
  • 2
  • 25
  • 45