attribute_helpers merged
As far as I can tell we weren't waiting for anything else to be done, so I've merged to master and pushed. Can we do a dev release today? hdp.
Re: Coercion problem
Hans Dieter Pearcey wrote: Excerpts from Emmanuel Quevillon's message of Wed Sep 02 10:47:06 -0400 2009: Attribute (cut_types) does not pass the type constraint because: Validation failed for 'ValidCutTypes' failed with value { blunt => [ "blunt" ] } at lib/Bio/Restriction/Analysis/FrameCutters.pm line 315 where as it is what I specified in my subtype definition? subtype 'ValidCutTypes' => as Dict[ cohesive => ArrayRef[Str], blunt=> ArrayRef[Str], ]; This means that both 'cohesive' and 'blunt' keys are required. See the Optional[] type constraint (also from Structured) if this isn't the case for you. Ok I'll have a look at it. Thanks! :) hdp.
Re: Coercion problem
Excerpts from Emmanuel Quevillon's message of Wed Sep 02 10:47:06 -0400 2009: > Attribute (cut_types) does not pass the type constraint because: > Validation failed for 'ValidCutTypes' failed with value { blunt => [ > "blunt" ] } at lib/Bio/Restriction/Analysis/FrameCutters.pm line 315 > where as it is what I specified in my subtype definition? > subtype 'ValidCutTypes' > => as Dict[ > cohesive => ArrayRef[Str], > blunt=> ArrayRef[Str], > ]; This means that both 'cohesive' and 'blunt' keys are required. See the Optional[] type constraint (also from Structured) if this isn't the case for you. hdp.
Re: Coercion problem
Hans Dieter Pearcey wrote: Hi Hans, Thanks for your quick reply. I followed your recommendations and used MX::Types::Structured and 'Dict'. However, I get an error when I am calling my constructor ->new() : Attribute (cut_types) does not pass the type constraint because: Validation failed for 'ValidCutTypes' failed with value { blunt => [ "blunt" ] } at lib/Bio/Restriction/Analysis/FrameCutters.pm line 315 where as it is what I specified in my subtype definition? and here is the code I wrote (followgin your advices): use Moose; use Moose::Util::TypeConstraints; use MooseX::Types::Moose qw/Str Int ArrayRef HashRef/; use MooseX::Types::Structured qw/Dict/; subtype 'ValidCutTypes' => as Dict[ cohesive => ArrayRef[Str], blunt=> ArrayRef[Str], ]; coerce 'ValidCutTypes' => from 'ArrayRef' => via { #Default value my $defaults = { cohesive => [qw/5' 3'/], blunt => [qw/blunt/] }; my $hash = { }; foreach my $type (@{$_}){ throw Bio::Root::BadParameter( "Wrong type value '$type' [cohesive|blunt]!") unless($defaults->{$type}); $hash->{$type} = $defaults->{$type}; } #[ map { $_ => $defaults->{$_} } @$_ ]; $hash; } => from 'HashRef' => via { ... } even if I use '[map { } @$_ ]'. The same probelm occured with passing a hash ref as : ->new(-cut_types => {cohesive => [qw/5'/]}) There's something I am not getting here. Any clue? Thanks > Some notes: > > * ArrayRef[Str] for the values in ValidCutTypes is just a guess based on your > existing defaults -- I don't know anything about your real problem domain. What I would like is an attribute supporting as argument: - arrayref which is transformed as a hashref of arrayref { $t => [qw/$r $g/] } - hashref which is just check for keys and values and returned as a hashref of array ref. > * You don't need to check the keys returned from the ArrayRef coercion, > because > the Dict[] type constraint will already do that. > * required => 1 is pretty much meaningless when you provide a default. > > > hdp. -- - Emmanuel Quevillon Biological Software and Databases Group Institut Pasteur +33 1 44 38 95 98 tuco at_ pasteur dot fr -
Re: Exception and attributes
Take a look at the Moose::Error stuff, all you need is in there. I also recommend looking at Try::Tiny and Throwable for the exceptions themselves. - Stevan On Sep 2, 2009, at 9:52 AM, Rolf Schaufelberger wrote: How can I make Mosse throw an user defined Exception (i.E from Exception::Class) when an attribute has a wrong type (or missing, etc) ? Make a new meta class for my attributes , and tell Moose to use that one ? Regards Rolf Schaufelberger
Exception and attributes
How can I make Mosse throw an user defined Exception (i.E from Exception::Class) when an attribute has a wrong type (or missing, etc) ? Make a new meta class for my attributes , and tell Moose to use that one ? Regards Rolf Schaufelberger
Re: Inversed logic when defining which attribute options can be changed
Hi, On Sat, Aug 29, 2009 at 10:28:05PM -0500, Chris Fields wrote: > Actually, the 'deny' vs. 'allowed' issue re: > legal_options_for_inheritance was brought up in this thread: > > http://thread.gmane.org/gmane.comp.lang.perl.moose/989/focus=990 > > Seemed like there was some consensus about using something like a 'deny' > list instead. Well, if I understood this issue correctly, that's exactly what my patch does. Sorry for confusing wording, if it's causing misunderstandment. Instead of specifying which options are allowed, you now specify which options aren't allowed (an empty list by default, thus all options are inheritable). PS. I'd be happy to get the topic committed to git://git.moose.perl.org, I'm going to ask more about that on IRC. Tuomas > > chris > > On Aug 29, 2009, at 7:29 PM, Tuomas Jormola wrote: > >> Hi, >> >> This was discussed about attribute options inheritance on IRC: >> >> 00:03 < tj> hi, any moose gurus around who could try explaining about >> the attribute options inheritance to a novice? >> 00:04 <@mst> start with which doc you've read and what wasn't clear >> 00:04 <@mst> we'll trade an explanation for a write-up for thre next >> guy :) >> 00:06 < tj> well i've read Moose::Manual::Attributes and read >> Moose::Meta::Attributes code >> 00:07 < tj> the docs and code states that you can only inherit a >> certain set of attributes defined in moose core >> 00:07 <@mst> yeah >> 00:07 < tj> why such an arbitrary limitation? >> 00:07 <+shadowpaste> "tj" at 217.168.144.84 pasted "sample code for >> question about @legal_options_for_inheritance" (21 lines) at >> http://scsys.co.uk:8001/33209 >> 00:07 < tj> i'd like to do something like that >> 00:08 <@mst> hrm >> 00:08 <@mst> I wonder if the MXMD stuff gets to add entries >> 00:09 < tj> i was wondering why attribute metaclasses can't define >> additional attribute options that are valid for inheritance >> 00:09 <@doy> they can >> 00:09 <@doy> this one just doesn't, apparently >> 00:10 < tj> ah ok >> 00:10 <@mst> honestly >> 00:10 <@mst> I think I'd much rather have a deny list than an allow >> list >> 00:10 <@doy> yeah >> 00:10 <@mst> wonder if we can covnince stevan of that :) >> 00:10 < tj> would save some trouble for module writers >> 00:10 <@mst> sure >> 00:10 <@mst> it'd also make it easier to shoot yourself in the foot >> 00:10 <@doy> i think we did at one point, and then nobody did anything >> about it >> 00:11 <@doy> but i might be misremembering >> 00:11 < tj> heh >> 00:11 < tj> someone care pointing the docs how to do that, i could >> patch MooseX::MetaDescription::Meta::Attribute and send it to upstream >> 00:12 < tj> just override legal_options_for_inheritance() ? >> 00:12 <@doy> around legal_options_for_inheritance => sub { >> 00:12 <@doy> yeah >> 00:13 < tj> let me try >> 00:20 < tj> ah but in my case it won't ever work, of course >> 00:21 < tj> since 'bar' is just an instance of Moose::Meta::Attribute >> metaclass, it doesn't magically become >> MooseX::MetaDescription::Meta::Attribute even if a subclass redefines >> the metaclass option >> 00:21 <@perigrin> mst: stevan has already said "yes" for making it a >> deny list >> 00:22 <@perigrin> nobody has done the work yet. >> 00:22 <@perigrin> well volunteered. >> 00:25 <@mst> tj: so there you go >> 00:26 <@mst> tj: all you have to do is invert the implementation and >> tweak the tests >> 00:26 <@rjbs> tj: you will win the accolades of all >> 00:27 <@perigrin> tj: information on patching Moose is in >> Moose::Manual::Contribution >> 00:27 < tj> ok could take a look >> >> So here's my try on this: >> http://scm.solitudo.net/gitweb?p=Moose.git;a=commitdiff;h=topics/inversed-legal-attribute-option-inheritance >> >> Feel free to merge/steal ideas from http://scm.solitudo.net/git/Moose.git >> branch topics/inversed-legal-attribute-option-inheritance. >> >> -- >> Tuomas Jormola > signature.asc Description: Digital signature