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
14
votes
3 answers

Multi-objective optimization example Pyomo

Any example for multi-objective optimization in Pyomo? I am trying to minimize 4 Objectives (Non Linear) and I would like to use pyomo and ipopt. Have also access to Gurobi. I want to see even very simple example where we try to optimize for two…
Golf Kilo Bravo
  • 143
  • 1
  • 1
  • 5
10
votes
1 answer

Type::Tiny and deep coercions

I'm trying to get deep coercions work with Type::Tiny without any success. From the manual it's said that: "Certain parameterized type constraints can automatically acquire coercions if their parameters have coercions. For example:…
PerC
  • 429
  • 3
  • 11
8
votes
2 answers

Why is my Moo object that inherits from a non-Moo class blessed into the parent's package for some modules?

I'm trying to create a Gtk3 application in Perl using GObject Introspection and Moo. There's a non-Moo class from Gtk, Gtk::ApplicationWindow, which I subclass through Moo using extends 'Gtk::ApplicationWindow'. The issue is that when an object of…
hsrv
  • 83
  • 4
8
votes
2 answers

Unblessing Perl objects and constructing the TO_JSON method for convert_blessed

In this answer I found a recommendation for a simple TO_JSON method, which is needed for serializing blessed objects to JSON. sub TO_JSON { return { %{ shift() } }; } Could anybody please explain in detail how it works? I changed it to: sub TO_JSON…
novacik
  • 1,497
  • 1
  • 9
  • 19
6
votes
1 answer

How to handle: Moo::Role's `before` modifier silently skipped due to circular imports?

Using Moo::Role, I'm finding that circular imports are silently preventing the execution of the before modifier of my method. I have a Moo::Role in MyRole.pm : package MyRole; use Moo::Role; use MyB; requires 'the_method'; before the_method => sub {…
6
votes
1 answer

Weakening captures using Sub::Quote

I'd like to weaken captured variables in the code generated by Sub::Quote. For example, here's the non-quoted alternative: use 5.10.0; use Scalar::Util qw[ weaken ]; { my $s = 'foo'; my $x = sub { say $s }; weaken( my $y = $x ); my $bar =…
Diab Jerius
  • 2,310
  • 13
  • 18
6
votes
2 answers

Real advantages of using Moo(se) over Perl OO

I am currently working at a company, where we are doing Perl development. However the code is really messy, uses really old Perl idioms, so I've decided to slowly clean it up and teach my coworkers about Modern::Perl, good software design, OOP -…
Davs
  • 489
  • 4
  • 12
6
votes
1 answer

Can I instantiate an object in Dancer to return a value to display?

I have the following code in my Dancer app module: package Deadlands; use Dancer ':syntax'; use Dice; our $VERSION = '0.1'; get '/' => sub { my ($dieQty, $dieType); $dieQty = param('dieQty'); $dieType = param('dieType'); if…
BackPacker777
  • 673
  • 2
  • 6
  • 21
5
votes
1 answer

How to use Types::Path::Tiny with Moo

My first question on this site, I come quickly. I'm a developer, I mainly use Python and Perl. I am passionate and I really like the development. My first question is about Perl, Moo, and Type::Tiny. Type::Tiny is a great module for use with Moo of…
Hobbestigrou
  • 1,777
  • 1
  • 13
  • 16
4
votes
3 answers

How to NOT execute trigger while constructing object

I have this code: package Foo; use Moo; has attr => ( is => "rw", trigger => 1 ); sub _trigger_attr { print "trigger! value:". shift->attr ."\n" } package main; use Foo; my $foo = Foo->new( attr => 1 ); $foo->attr( 2 ); It returns: $ perl…
gib
  • 738
  • 1
  • 8
  • 16
4
votes
1 answer

"Connecting" a Moo object with a hash

In my real code I want to "synchronize" a Moo (or Moose if Moo won't work) object with a hash (in reality a tied hash), so that reading a property of the Moo object would read the corresponding value from the hash and writing a property of the Moo…
porton
  • 5,214
  • 11
  • 47
  • 95
4
votes
2 answers

In Moose, if a role defines an attribute with a default, how do I change that default in my consuming class?

My Moose class consumes a role which I'm not allowed to change. That role defines an attribute with a default. I need my class to have that attribute, but with a different default. Is that possible? All I could come up with is surrounding the "new"…
alexk
  • 1,488
  • 1
  • 12
  • 17
4
votes
4 answers

How to declare 2 dependant attributes in Mooseish way?

In my object constructor i had statement to initialize two attributes same time: ($self->{token}, $self->{token_start}) = $self->_get_authorized_token(); So i got token and it's starting time together in one statement. Now i try to port my module…
w.k
  • 8,218
  • 4
  • 32
  • 55
3
votes
2 answers

Moo, lazy attributes, and default/coerce invocation

My Moo based class has both lazy & non-lazy attributes which have both default and coerce subs. If I don't initialize the attributes I'm finding that both default and coerce subs are called for the normal attribute, but only default is called for…
Diab Jerius
  • 2,310
  • 13
  • 18
3
votes
1 answer

How can I lift an attribute constraint depending on another attribute from a trigger into a type refinement?

This works: use Moops; class Foo :ro { use Types::Common::Numeric qw(PositiveOrZeroInt); has from => required => true, isa => PositiveOrZeroInt; has to => required => true, isa => PositiveOrZeroInt, trigger => method($to) { die…
daxim
  • 39,270
  • 4
  • 65
  • 132
1
2 3 4