moose

How can I build multiple attributes with a single builder in Moose?

只谈情不闲聊 提交于 2019-11-30 14:13:16
Using Moose, is it possible to create a builder that builds multiple attributes at once? I have a project in which the object has several 'sets' of fields - if any member of the set is requested, I want to go ahead and populate them all. My assumption is that if I need the name, I'll also need the birthdate, and since they're in the same table, it's faster to get both in one query. I'm not sure if my question is clear enough, but hopefully some sample code will make it clear. What I have: Package WidgetPerson; use Moose; has id => (is => 'ro', isa => 'Int' ); has name => (is => 'ro', lazy => 1

How can I access the meta class of the module my Moose role is being applied to?

ⅰ亾dé卋堺 提交于 2019-11-30 13:36:58
问题 I'm using Moose roles to apply some wrapper behaviour around some accessor methods in a class. I want to apply this role to a number of modules, each of which have a different set of attributes whose accessors I want to wrap. Is there a way to access the meta class of the module being applied to, from within the role? i.e. something like this: package My::Foo; use Moose; with 'My::Role::X'; has [ qw(attr1 attr2) ] => ( is => 'rw', # ... ); has 'fields' => ( is => 'bare', isa => 'ArrayRef[Str]

How can I access the meta class of the module my Moose role is being applied to?

五迷三道 提交于 2019-11-30 07:37:06
I'm using Moose roles to apply some wrapper behaviour around some accessor methods in a class. I want to apply this role to a number of modules, each of which have a different set of attributes whose accessors I want to wrap. Is there a way to access the meta class of the module being applied to, from within the role? i.e. something like this: package My::Foo; use Moose; with 'My::Role::X'; has [ qw(attr1 attr2) ] => ( is => 'rw', # ... ); has 'fields' => ( is => 'bare', isa => 'ArrayRef[Str]', default => sub { [qw(attr1 attr2) ] }, ); 1; package My::Role::X; use Moose::Role; # this should be

How to make Mason2 UTF-8 clean?

人走茶凉 提交于 2019-11-30 06:53:03
问题 Reformulating the question, because @optional asked me it wasn't clear and linked one HTML::Mason based solution Four easy steps to make Mason UTF-8 Unicode clean with Apache, mod_perl, and DBI , what caused confusions the original is 4 years old and meantime (in 2012) the "poet" is created Comment: This question already earned the "popular question badge", so probably i'm not the only hopeless person. :) Unfortunately, demonstrating the full problem stack leads to an very long question and

How can I build multiple attributes with a single builder in Moose?

给你一囗甜甜゛ 提交于 2019-11-29 20:48:15
问题 Using Moose, is it possible to create a builder that builds multiple attributes at once? I have a project in which the object has several 'sets' of fields - if any member of the set is requested, I want to go ahead and populate them all. My assumption is that if I need the name, I'll also need the birthdate, and since they're in the same table, it's faster to get both in one query. I'm not sure if my question is clear enough, but hopefully some sample code will make it clear. What I have:

What is the best option for building a plugin system for a Moose application?

南楼画角 提交于 2019-11-29 00:24:38
I want to write a app that can be extended via plugins, using Perl and Moose . I know there are a few Moose modules for writing plugins and I know there are other ways. What are my options? and what should I know about them? any thing I should think about before implementing a plugin system? There are a few ways to provide extensibility; allow the user to apply roles to your class, or allow them to pass in small objects that do the interesting things (delegates). Delegates perform better than roles, but will require that you plan for all the extensibility up front. Roles allow more ad-hoc

How to make Mason2 UTF-8 clean?

南笙酒味 提交于 2019-11-28 23:01:43
Reformulating the question, because @optional asked me it wasn't clear and linked one HTML::Mason based solution Four easy steps to make Mason UTF-8 Unicode clean with Apache, mod_perl, and DBI , what caused confusions the original is 4 years old and meantime (in 2012) the "poet" is created Comment: This question already earned the "popular question badge", so probably i'm not the only hopeless person. :) Unfortunately, demonstrating the full problem stack leads to an very long question and it is very Mason specific. First, the opinions-only part :) I'm using HTML::Mason over ages, and now

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

守給你的承諾、 提交于 2019-11-28 11:17:21
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 enable Foo->$hash{func} to work? (EDIT: I don't mean to do anything special by calling a method on class

What is the best option for building a plugin system for a Moose application?

和自甴很熟 提交于 2019-11-27 21:28:52
问题 I want to write a app that can be extended via plugins, using Perl and Moose. I know there are a few Moose modules for writing plugins and I know there are other ways. What are my options? and what should I know about them? any thing I should think about before implementing a plugin system? 回答1: There are a few ways to provide extensibility; allow the user to apply roles to your class, or allow them to pass in small objects that do the interesting things (delegates). Delegates perform better

How can I flexibly add data to Moose objects?

本小妞迷上赌 提交于 2019-11-27 18:26:36
问题 I'm writing a module for a moose object. I would like to allow a user using this object (or myself...) add some fields on the fly as he/she desires. I can't define these fields a priori since I simply don't know what they will be. I currently simply added a single field called extra of type hashref which is is set to rw , so users can simply put stuff in that hash: # $obj is a ref to my Moose object $obj->extra()->{new_thingie}="abc123"; # adds some arbitrary stuff to the object say $obj-