Skip Menu |

This queue is for tickets about the MooseX-AttributeCloner CPAN distribution.

Report information
The Basics
Id: 74726
Status: resolved
Priority: 0/
Queue: MooseX-AttributeCloner

People
Owner: Nobody in particular
Requestors: mg8 [...] sanger.ac.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



CC: Andy Brown <setitesuk [...] gmail.com>
Subject: cloned command line should not contain attributes whose metaclass is MooseX::Getopt::Meta::Attribute::NoGetopt: proposed patch for MooseX-AttributeCloner-0.24
Date: Mon, 06 Feb 2012 16:36:15 +0000
To: bug-MooseX-AttributeCloner [...] rt.cpan.org
From: Marina Gourtovaia <mg8 [...] sanger.ac.uk>
Hi Andy The attribute clone clones attributes to the command line even if they are explicitly set as not accepted from the command line (their metaclass set to MooseX::Getopt::Meta::Attribute::NoGetopt). I am going to patch our version of the module. The patch follows at the end of the e-mail. If you release a CPAN update, I'd be grateful if you let us know so that we could update our version from CPAN. Kind regards Marina Gourtovaia diff -ruN MooseX-AttributeCloner-0.24/Changes MooseX-AttributeCloner-0.24.mg8/Changes --- MooseX-AttributeCloner-0.24/Changes 2011-04-23 08:58:43.000000000 +0100 +++ MooseX-AttributeCloner-0.24.mg8/Changes 2012-02-06 16:23:18.565377000 +0000 @@ -2,6 +2,9 @@ --------------- release 0.24 + - if the metaclass of the attribute is MooseX::Getopt::Meta::Attribute::NoGetopt, do not copy it to the command line since it will not be accepte d + +release 0.24 - addition of attributes_as_hashref method, returning built attributes as a hashref release 0.23 diff -ruN MooseX-AttributeCloner-0.24/lib/MooseX/AttributeCloner.pm MooseX-AttributeCloner-0.24.mg8/lib/MooseX/AttributeCloner.pm --- MooseX-AttributeCloner-0.24/lib/MooseX/AttributeCloner.pm 2011-04-23 08:58:43.000000000 +0100 +++ MooseX-AttributeCloner-0.24.mg8/lib/MooseX/AttributeCloner.pm 2012-02-06 16:01:22.940680000 +0000 @@ -13,6 +13,8 @@ our $VERSION = 0.24; +Readonly::Scalar our $ATTRIBUTE_METACLASS_TO_SKIP => q[MooseX::Getopt::Meta::Attribute::NoGetopt]; + =head1 NAME MooseX::AttributeCloner @@ -137,7 +139,7 @@ # version 0.21 - force this to be in a sorted order, so that results can be consistent should operating systems return keys in a different order foreach my $key (sort keys %{$attributes}) { - if (! ref $attributes->{$key}) { + if (! ref $attributes->{$key} && (ref( $self->meta()->get_attribute($key) ) ne $ATTRIBUTE_METACLASS_TO_SKIP )) { my $string = $self->_create_string($key, $attributes->{$key}, $arg_refs); push @command_line_options, $string; next; diff -ruN MooseX-AttributeCloner-0.24/t/10-AttributeCloner.t MooseX-AttributeCloner-0.24.mg8/t/10-AttributeCloner.t --- MooseX-AttributeCloner-0.24/t/10-AttributeCloner.t 2011-04-23 08:58:43.000000000 +0100 +++ MooseX-AttributeCloner-0.24.mg8/t/10-AttributeCloner.t 2012-02-06 16:16:46.586372000 +0000 @@ -2,7 +2,7 @@ use warnings; use Carp; use English qw{-no_match_vars}; -use Test::More tests => 39; +use Test::More tests => 42; use Test::Exception; use lib qw{t/lib}; use JSON; @@ -40,7 +40,9 @@ lives_ok { $cloned_object = $object_to_clone->new_with_cloned_attributes(q{TestNewAttributeCloner},$arg_refs); } q{new_with_cloned_attributes ra n ok}; ok(!$cloned_object->has_attr1(), q{no attr1 value, so nothing passed through and not set}); is($cloned_object->attr8(), q{test8}, q{attr8 value passed through ok from the arg_refs provided}); - + is($cloned_object->attr7(), q{test7}, q{attribute with MooseX::Getopt::Meta::Attribute::NoGetopt metaclass gets cloned to another object}); + is(ref $cloned_object->meta()->get_attribute(q[attr7]), q[MooseX::Getopt::Meta::Attribute::NoGetopt], 'its metaclass is MooseX::Getopt::Meta::At tribute::NoGetopt'); + is($cloned_object->attributes_as_command_options, q[--attr2 test2 --attr6 test6 --attr8 test8], 'but it is not cloned to the command line'); my $hash_ref = { key1 => q{val1}, key2 => q{val2}, key_obj => $cloned_object}; my $array_ref = [1,2,3,$hash_ref,$object_to_clone]; @@ -62,8 +64,6 @@ ok(ref$hash_key_object, q{$cloned_ref_test->hash_attr() is a ref}); is($cloned_ref_test->array_attr()->[3],$hash_ref, q{array maintained}); - - my $json_string = q[{"hash_attr":{"key2":"val2","key1":"val1"},"attr2":"0","attr1":"test1","array_attr":[1,2,3,{"key2":"val2","key1":"val1"},nul l]}]; my $json_test_hash = from_json($json_string); diff -ruN MooseX-AttributeCloner-0.24/t/lib/TestNewAttributeCloner.pm MooseX-AttributeCloner-0.24.mg8/t/lib/TestNewAttributeCloner.pm --- MooseX-AttributeCloner-0.24/t/lib/TestNewAttributeCloner.pm 2011-04-23 08:58:43.000000000 +0100 +++ MooseX-AttributeCloner-0.24.mg8/t/lib/TestNewAttributeCloner.pm 2012-02-06 16:14:34.199700000 +0000 @@ -12,6 +12,7 @@ has q{attr8} => (isa => q{Str}, is => q{ro}); has q{attr9} => (isa => q{Str}, is => q{ro}); has q{attr10} => (isa => q{Str}, is => q{ro}); +has q{attr7} => (isa => q{Str}, is => q{ro}, metaclass => 'NoGetopt',); -- The Wellcome Trust Sanger Institute is operated by Genome Research Limited, a charity registered in England with number 1021457 and a company registered in England with number 2742969, whose registered office is 215 Euston Road, London, NW1 2BE.
patch went out in v0.25