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

How do I best make triggered accessors with defaults in Moose?

I have a situation where I'd like to cache some calculations for use later. Let's say I have a list of allowed values. Since I'm going to be checking to see if anything is in that list I'm going to want it as a hash for efficiency and convenience.…
Schwern
  • 153,029
  • 25
  • 195
  • 336
7
votes
2 answers

How can I declare a class variable as floating point in Moose?

How can I declare a class variable as floating point in Moose? My (fictional) sample below produces errors for "Real", "Number" etc ... "Str" works but defeats the purpose .. searching/Google doesn't help, since I can't hit the correct search…
lexu
  • 8,766
  • 5
  • 45
  • 63
6
votes
4 answers

How to make a method "final" in Perl?

I was wondering if it is possible to make sure a method in a class I make will NOT be monkey patched (Monkey patch). Can Moose achieve this? Consider the following: { package Foo; sub hello{print "HI"} 1; } package main; sub Foo::hello {print…
Беров
  • 1,383
  • 10
  • 22
6
votes
1 answer

using localtime inside moose default values

What's wrong with the code below ? When run, I get: "Use of uninitialized value in concatenation (.) or string at ./main.pl line 14" #!/usr/bin/perl package Test; use Moose; has 'message' => (isa => 'HashRef', is => 'ro', default =>…
mbonnin
  • 6,893
  • 3
  • 39
  • 55
6
votes
5 answers

Why doesn't a subclass inherit its parent's constants?

So I was going about my Moosey business and I thought hey might be nice to use a constant in these places where I'm using numbers, to make it clear what these numbers mean or in case they change later So in the parent class I added the standard…
qodeninja
  • 10,946
  • 30
  • 98
  • 152
6
votes
1 answer

Why is the "lazy_build" feature in Moose discouraged?

The documentation for the lazy_build feature in Moose has this to say: Note that use of this feature is strongly discouraged. Some documentation used to encourage use of this feature as a best practice, but we have changed our minds. However, it…
Wouter Verhelst
  • 1,269
  • 1
  • 12
  • 27
6
votes
2 answers

AttributeError: module 'cv2.cv2' has no attribute 'TrackerMOSSE_create'

As the Dan's suggestion, i tried to edit this post Error occurred at setting up MOOSE tracker, I also don't know why this error happened because i installed the Opencv-contrib-python==4.5.1.48.However,aftering installing it,the error is still there.…
Chuyên Hoàng
  • 108
  • 1
  • 3
  • 8
6
votes
2 answers

Moose or Meta?

I've been trying to do this a number of ways, but none of them seem graceful enough. (I'm also wondering if CPAN or Moose already has this. The dozens of searches I've done over time have shown nothing that quite matches.) I want to create a type…
Axeman
  • 29,660
  • 2
  • 47
  • 102
6
votes
2 answers

How come MooseX::Storage doesn't seem to follow attribute traits for some objects?

I have put together a little test case to demonstrate my problem: package P1; use Moose; use MooseX::Storage; with Storage; has 'blah' => ( is => 'rw', ); package P2; use Moose; use MooseX::Storage; with Storage; has 'lol' => ( is =>…
ocharles
  • 6,172
  • 2
  • 35
  • 46
6
votes
3 answers

Apply specific check (beyond Moose types) to Moose attribute

Moose types are great, but sometimes you need to be more specific. You all know these data type rules: that parameter may only be 'A', 'B' or 'C', or only a currency symbol, or must conform to some regular expression. Take a look at the following…
Lumi
  • 14,775
  • 8
  • 59
  • 92
6
votes
2 answers

How can you create private/public variable and functions using Moose?

I am going through the Moose recipes and I still cannot see if I can create private variables and functions using it? Is it possible? If yes how to create them with Moose?
Gaurav Dadhania
  • 5,167
  • 8
  • 42
  • 61
6
votes
1 answer

When should I make a Moose class immutable when I'm actually using ->meta?

Normally I would finalize a class at compilation via __PACKAGE__->meta->make_immutable at the end of the class. However, when should I be making a class immutable that composes roles into itself at runtime? Should I even be doing so to get better…
Oesor
  • 6,632
  • 2
  • 29
  • 56
6
votes
2 answers

Perl OO using Moose - best way to code delegation example?

Perl's Moose is different from other object systems, so it's not always clear how to translate an example known from other languages into Moose lingo. Consider the following Java example of Rectangle and Square, where a Square instance (a square…
Lumi
  • 14,775
  • 8
  • 59
  • 92
6
votes
3 answers

How can I declare/use static members in Moose?

I am using Moose objects, but I need to declare static members for things that will be done just once and are not object related. Do you have any ideas or examples? Thanks Dotan.
Dotan
  • 61
  • 2
6
votes
3 answers

How can I make all lazy Moose features be built?

I have a bunch of lazy features in a Moose object. Some of the builders require some time to finish. I would like to nvoke all the builders (the dump the "bomplete" object). Can I make all the lazy features be built at once, or must I call each…
David B
  • 29,258
  • 50
  • 133
  • 186