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

Perl with Moo: How to call superclass's implementation of a method?

I have a class X with a subclass Y. X has a method calculate() that I'd like to override in Y with some additional behaviour, an if statement that, if it fails, call X.calculate(). In Python this would be accomplished with: class X(object): …
dmn
  • 965
  • 3
  • 13
  • 24
2
votes
1 answer

Watch change of attribute inside Perl class

Can anyone provide a code example how do you set watchers on variable change inside of class ? I tried to do it several ways using different features (Scalar::Watcher, trigger attribute of Moo) and OOP frameworks (Moo, Mojo::Base) and but all…
Paul Serikov
  • 2,550
  • 2
  • 21
  • 36
2
votes
1 answer

Moo/Moose attributes - how “keys %$self” works?

In my last question I asked many unrelated things, and can't accept multiple answers what answers only some questions, so here is clearly (i hope) defined question about the (Moo) attributes. use 5.010; use strict; use warnings; package…
novacik
  • 1,497
  • 1
  • 9
  • 19
2
votes
1 answer

Dynamic Moo object methods change

I am using Moo as my OO engine, and I want to change the behaviour of some instances at runtime. I need to add new methods and change the existing ones. Is that possible with Moo? If not, how can I achieve this?
Miguel Prz
  • 13,718
  • 29
  • 42
2
votes
3 answers

Perl ORM with Moo

I'd like to use Moo as the Object Oriented approach for my app (with a relational database). I had used DBIx::Class & Rose::DB::Object in the past, but these distributions are not Moo (neither Moose) related. I am looking for an ORM (or similar)…
Miguel Prz
  • 13,718
  • 29
  • 42
1
vote
0 answers

How to use Class:DBI with own constructors or OO-systems like Moo(se)?

When using Class::DBI in Perl, the insert() method from Class::DBI acts as a constructor returning an object. How can I use Class::DBI in combination with object attributes that are not part of any database tables? For example: I would like to have…
ilonw
  • 19
  • 1
1
vote
1 answer

How to get a code reference from a object method using Moo

I'm using Moo (OO) under Perl v5.26 and Linux. I'm writing tests and have some kind of runtime dictionary in an object to store states of an application. I want to test if a defined code reference points to the adequate method in that object. My…
huckfinn
  • 644
  • 6
  • 23
1
vote
1 answer

My programing language's Lexer will not process NEWLINE (done with moo js)

I'm creating a new programing language just for fun and to know understand languages at more basic level. I started with writing a lexer with moo js and everything is working fine except for NEWLINE. I tried many things but it just won't resolve. I…
1
vote
1 answer

How to we dynamically create missing attributes in Moo or Moose?

We have a sample code like below. Is it possible to to capture all missing attributes invoked in package FooBar and create it dynamically? This is something like PHP's __call. test.pl package Person; use feature qw(say); use Moo; has name => (is =>…
1
vote
0 answers

Can't use Moo class properly before it's declaration in the same script

Please have a look at the script below. The first call to do_stuff(...), although it works without errors, prints names: $VAR1 = undef;. The second call to do_stuff(...), works as I expect it to work and prints names: $VAR1 = 'Second Name'; And i…
Dragos Trif
  • 276
  • 1
  • 12
1
vote
1 answer

How can I implement "thunks" (delayed computation) in a general way using Moo and Type::Tiny?

I want to be able to have a Moo* class with these characteristics: an object's attribute can store a reference to the object itself that attribute will be type-constrained using a Type::Tiny type so the reference must be of the right type the class…
Ed.
  • 1,992
  • 1
  • 13
  • 30
1
vote
1 answer

Attribute delegation in Perl Moose or Moo

Initially topic was started here, but I need a working code example how to properly delegate attributes with Moo or Moose. Based on documentation I wrote this code to check: package Cat; use Moo; has 'token' => ( is => 'rw', default => '12345'…
Paul Serikov
  • 2,550
  • 2
  • 21
  • 36
1
vote
1 answer

Moo: Add attribute to another (non-current) package

The following is a simplified example of my real code: #!/usr/bin/perl package X; use Moo; sub add_attr_for_another_package { my ($package) = @_; eval "package $package"; has 'q' => (is=>'rw', default=>123); } package Y; use…
porton
  • 5,214
  • 11
  • 47
  • 95
1
vote
1 answer

Automatic conversion of empty string to undef in Perl Moo objects

For some fields of a Perl Moo object I want to replace empty string when it is assigned to the field with undef. That is I want: $obj->x("") to make the field x undefined. Please help to develop a Moo extension which does this. A possible way to do…
porton
  • 5,214
  • 11
  • 47
  • 95
1
vote
1 answer

Perl Moo, dynamically generated accessors

I try to turn Perl closures into Moo accessors, as in the following code. Unfortunately the code works with Moose but throws an exception with Moo. Please help me to write a Moo code with read and write accessors defined by Perl closures (not the…
porton
  • 5,214
  • 11
  • 47
  • 95