moose

OO Design Patterns with Perl

自闭症网瘾萝莉.ら 提交于 2019-12-22 08:18:07
问题 I am currently planning the design for a new system I will need to code that interacts with a back-end API. I was contemplating object composition and inheritance and decided that the most correct procedure in my situation would be to go with composition over inheritance as my objects have a "has a" relationship to one another and not an "is a". I find now though that because some objects are reliant on other, there may be cases were "object A" has an attribute which is "object B" and an

Is it “OK” to wrap standard Perl modules with Moose?

半腔热情 提交于 2019-12-22 06:33:14
问题 Many standard modules are all using straight up perl -- problem is these guys arent using Moosey stuff, so I catch myself wrapping them with Moose or reinventing some simple functions in bigger libraries for convenience. I wondered if there was any general approach to how developers using Moose incorporate other libraries that are non-Moose. Being new to Perl and Moose I'd like to have a better understanding of how Moose is used in situations like this, or when it is generally preferred to

In Perl/Moose, how can I apply a modifier to a method in all subclasses?

喜夏-厌秋 提交于 2019-12-22 03:48:13
问题 I have a Moose class that is intended to be subclassed, and every subclass has to implement an "execute" method. However, I would like to put apply a method modifier to the execute method in my class, so that it applies to the execute method in all subclasses. But method modifiers are not preserved when a method is overriden. Is there any way to ensure that all subclasses of my class will have my method modifier applied to their execute methods? Example: In a superclass, I have this: before

Succinct MooseX::Declare method signature validation errors

谁说胖子不能爱 提交于 2019-12-20 14:24:08
问题 I've been a proponent of adopting Moose (and MooseX::Declare) at work for several months. The style it encourages will really help the maintainability of our codebase, but not without some initial cost of learning new syntax, and especially in learning how to parse type validation errors. I've seen discussion online of this problem, and thought I'd post a query to this community for: a) known solutions b) discussion of what validation error messages should look like c) propose a proof of

Succinct MooseX::Declare method signature validation errors

只愿长相守 提交于 2019-12-20 14:22:36
问题 I've been a proponent of adopting Moose (and MooseX::Declare) at work for several months. The style it encourages will really help the maintainability of our codebase, but not without some initial cost of learning new syntax, and especially in learning how to parse type validation errors. I've seen discussion online of this problem, and thought I'd post a query to this community for: a) known solutions b) discussion of what validation error messages should look like c) propose a proof of

Are MooseX::Declare and MooseX::Method::Signatures production ready?

橙三吉。 提交于 2019-12-20 13:01:31
问题 From the current version (0.98) of the Moose::Manual::MooseX are the lines: We have high hopes for the future of MooseX::Method::Signatures and MooseX::Declare. However, these modules, while used regularly in production by some of the more insane members of the community, are still marked alpha just in case backwards incompatible changes need to be made. I noticed that for MooseX::Method::Signatures the change log for September 2009 mentions the removal of the " scary ALPHA disclaimer ". So,

Which recommended Perl modules can serialize Moose objects?

99封情书 提交于 2019-12-19 09:53:37
问题 I was usually using Storable with nstore , but now I have a module that has CODE and apparently Storable doesn't like that. I found YAML (and YAML::XS which I can't really get to work). I also experimented a bit with MooseX::Storage without much success. Are there other alternatives? What would you recommend? 回答1: You can dump a coderef with Data::Dumper after setting $Data::Dumper::Deparse to a true value, but this is only intended for debugging purposes, not for serialization. I would

How can I find all the packages that inherit from a package in Perl?

纵饮孤独 提交于 2019-12-19 09:05:16
问题 I have a number of different sites that I download data from and massage into other formats (using Perl) for use at work, that are all run from one Perl script kinda like so: #! /usr/bin/perl use strict; use My::Package1; use My::Package2; my $p1 = My::Package1->new; $p1->download; my $p2 = My::Package2->new; $p2->download; and so on and so forth. At the moment each My::Package is its own package; it doesn't inherit from a base package or anything. I am planning to re-write them using Moose

How do I call a function name that is stored in a hash in Perl?

て烟熏妆下的殇ゞ 提交于 2019-12-17 19:43:10
问题 I'm sure this is covered in the documentation somewhere but I have been unable to find it... I'm looking for the syntactic sugar that will make it possible to call a method on a class whose name is stored in a hash (as opposed to a simple scalar): use strict; use warnings; package Foo; sub foo { print "in foo()\n" } package main; my %hash = (func => 'foo'); Foo->$hash{func}; If I copy $hash{func} into a scalar variable first, then I can call Foo->$func just fine... but what is missing to

Multiple inheritance from a shared base class in Perl Moose

两盒软妹~` 提交于 2019-12-14 03:22:23
问题 Let A, B, C, D be Moose classes. Let both B and C inherit from A. Let also D inherit from both B and C. What will happen with "duplicate" properties (properties from A present in both B and C)? 回答1: See Method Dispatch Order in Modern Perl : Method dispatch order (or method resolution order or MRO) is obvious for single-parent classes. Look in the object's class, then its parent, and so on until you find the method or run out of parents. Classes which inherit from multiple parents (multiple