Questions tagged [moo]

Moo is a minimal object-oriented programming library for the Perl programming language.

Moo is a minimal object-oriented programming library for the Perl programming language.

  • For the similarly named Java object-object mapping tool, see object-object-mapping.
  • For the the CodeIgniter plugin image-moo, see codeigniter.
  • For object-oriented MUD programming, see mud.
  • For the MooTools Javascript framework, see mootools.
56 questions
3
votes
0 answers

Readonly mutators with Moo

I'd like to have an immutable objects with modifiable fields, so that $foo->bar() returns the bar of foo, and $foo->bar(42) returns a new object with bar set to 42, leaving $foo intact. Of course, I can do that with Moo[se]: package Foo; use…
Dallaylaen
  • 5,268
  • 20
  • 34
3
votes
1 answer

Dynamically modifying methods in Moo using the published Moo API

I'm trying to stick to the published API to dynamically modify methods in Moo, and have not come up with a general solution. First off, some code: package R1 { use Moo::Role; sub r1 { say __PACKAGE__ } } package C1 { use Moo; sub c1…
Diab Jerius
  • 2,310
  • 13
  • 18
3
votes
1 answer

Cryptic Moo (Perl) Error "Attempt to bless into a reference at..."

Probably a long shot but I'm wondering if anyone has seen an error like this before, as I can not reproduce it outside of a production environment. Essentially the situation is as follows: I have a module called My::Budget::Module (renamed for…
mshirlaw
  • 168
  • 1
  • 10
3
votes
1 answer

Modifiers not visible under objects from services

Given the following: Moo 2.001001; Bread::Board 0.34; a Bread::Board container base class Foo with property str and around modifier for str subclass Bar extending Foo The issue: [GOOD] when instantiating object from plain Bar, Foo::str modifier…
Vlad Ghita
  • 59
  • 7
3
votes
2 answers

How to change attribute types? (Perl Moo)

We use Perl Moo. Let there is defined a set of attributes: package C; use Moo; use Types::Standard qw(Str Int Num Maybe); has 'x' => (is=>'rw', isa=>Str); has 'y' => (is=>'rw', isa=>Int); has 'z' => (is=>'rw', isa=>Int); # here to insert…
porton
  • 5,214
  • 11
  • 47
  • 95
3
votes
1 answer

perl Test::MockModule with DB acces

I'm starting in the unit testing world in Perl. Here is my question: I have a class in Perl (I'm using Moo BTW) and this class has 3 attributes (I'm going to put the code bellow). One of these attributes is an array, and it is generated…
the_ccalderon
  • 2,006
  • 2
  • 13
  • 24
3
votes
1 answer

Run coercions inside a Type::Tiny custom constraint?

I have a custom DateTime type that has a coercion defined on it from string to DateTime, like so: package Library; use Type::Library -base, -declare => qw(DateTime); use DateTime::Format::ISO8601; class_type DateTime, { class => 'DateTime'…
Aurelia Peters
  • 2,169
  • 1
  • 20
  • 34
3
votes
1 answer

Is there a way to override the constructor in Moo?

I am working on a MooX module that needs to add a wrapper around the constructor. I've tried method modifies or having the import method directly change *{"${target}::new"} with no effect. So how can I do this?
Rob
  • 781
  • 5
  • 19
3
votes
2 answers

How to pass multiple arguments to a setter/writter in Perl Moo

I started to migrate a couple of Perl modules to Moo but got stuck because the setter/writer can only have one single argument (can't it?). This also applies to coercing: package MyThing: use Moo; use Scalar::Util qw(blessed); use…
Jakob
  • 3,570
  • 3
  • 36
  • 49
2
votes
2 answers

Nearley. How to resolve grammar Nearley use JS syntax

Let's say I have some kind of grammar, but it works by itself, but the JS code does not recognize it. Is there such an option so that you can combine the code of your grammar and syntax in one. Let's say I have this grammar (Nearley +…
Tim
  • 17
  • 5
2
votes
0 answers

DateTime Won't Load Properly Unless a Module Using Moo Launches First

I'm cleaning up code and removed the now deprecated Forecast::IO module from my Perl script. When I did, I started getting this error: [root@server cgi-bin]# perl Weather.pm Undefined subroutine &B::perlstring called at…
Timothy R. Butler
  • 1,097
  • 7
  • 20
2
votes
1 answer

ANTLR Lexer matching the wrong rule

I'm working on a lexer and parser for an old object oriented chat system (MOO in case any readers are familiar with its language). Within this language, any of the below examples are valid floating point numbers: 2.3 3. .2 3e+5 The language also…
WiredWiz
  • 646
  • 8
  • 18
2
votes
3 answers

How do I check if an object is valid when pushed to an ArrayOf[] member in my perl Moo class?

I have created a Moo class containing an array of objects which is checked against a type using Types::Standard and I want to verify that I'm placing the right objects into that array without hard-coding too much. Here is an example of what I have…
pipe
  • 657
  • 10
  • 27
2
votes
2 answers

Does setting a writer name for a Moo read-only attribute make it read-write?

I'm studying Moo and bumped into this basic question. If I set an accessor or a writer name for a read-only attribute the attribute becomes writable. Do accessors or writers imply that the attribute is writable even if it's set to read-only (is =>…
felima
  • 91
  • 6
2
votes
1 answer

Why does Moo's builder method have access to only some of the other attributes?

I was expecting a builder method to have access to all the other attributes provided by the caller. But it seems it only has access to those whose name is alphabetically less than the current attribute's. E.g. why can the builder for b here see the…
Peter V. Mørch
  • 13,830
  • 8
  • 69
  • 103