Skip Menu |

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

Report information
The Basics
Id: 58223
Status: open
Priority: 0/
Queue: MooseX-Getopt-Defanged

People
Owner: Nobody in particular
Requestors: whatson [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: v1.16.0
Fixed in: (no value)



Subject: Inherited options do not work
Hi, MooseX::Getopt::Defanged does not currently support inherited options, due to a bug in the method used to find attributes with the MooseX::Getopt::Defanged::Option trait. The scanned attributes are currently found via $class->meta->get_attribute_names(), which will only return attributes declared in $class - it doesn't check the class heirarchy. I've attached a patch that adds a test for inherited options, and fixes the bug by using $class->meta->get_all_attributes() which checks the class heirarchy correctly. Regards, Andrew Whatson
Subject: moosex_getopt_defanged_inheritance.diff
=== modified file 'lib/MooseX/Getopt/Defanged.pm' --- lib/MooseX/Getopt/Defanged.pm 2010-06-08 01:53:42 +0000 +++ lib/MooseX/Getopt/Defanged.pm 2010-06-08 02:01:35 +0000 @@ -62,7 +62,7 @@ grep { $_->does('MooseX::Getopt::Defanged::Meta::Attribute::Trait::_Getopt') } - map { $metadata->get_attribute($_) } $metadata->get_attribute_list(); + $metadata->get_all_attributes(); return \@option_attributes; } # end _getopt_get_option_attributes() === added file 't/inheritance.t' --- t/inheritance.t 1970-01-01 00:00:00 +0000 +++ t/inheritance.t 2010-06-08 04:56:11 +0000 @@ -0,0 +1,42 @@ +#!/usr/bin/env perl + +package My::Class; + +use Moose; + +with 'MooseX::Getopt::Defanged'; + +has test1 => (traits => ['MooseX::Getopt::Defanged::Option'], is => 'ro', isa => 'Str'); +has test2 => (traits => ['MooseX::Getopt::Defanged::Option'], is => 'ro', isa => 'Str'); + +__PACKAGE__->meta->make_immutable; + +package My::Class::Extended; + +use Moose; + +extends 'My::Class'; + +has test3 => (traits => ['MooseX::Getopt::Defanged::Option'], is => 'ro', isa => 'Str'); +has test4 => (traits => ['MooseX::Getopt::Defanged::Option'], is => 'ro', isa => 'Str'); + +__PACKAGE__->meta->make_immutable; + +package main; + +use strict; +use warnings; +use Test::More tests => 1; +use Test::Exception; + +lives_ok( + sub { + My::Class::Extended->new->parse_command_line([qw( + --test1 test1 + --test2 test2 + --test3 test3 + --test4 test4 + )]); + }, + 'inherited options work' +);
Subject: Re: [rt.cpan.org #58223] Inherited options do not work
Date: Wed, 09 Jun 2010 07:08:55 -0500
To: bug-MooseX-Getopt-Defanged [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
On 6/8/10 12:12 AM, Andrew Whatson via RT wrote: Show quoted text
> MooseX::Getopt::Defanged does not currently support inherited options, > due to a bug in the method used to find attributes with the > MooseX::Getopt::Defanged::Option trait. > > The scanned attributes are currently found via > $class->meta->get_attribute_names(), which will only return attributes > declared in $class - it doesn't check the class heirarchy.
Ah, whoops. Sorry about that. I've never run into this because I only use roles for composition and no inheritance. Show quoted text
> I've attached a patch that adds a test for inherited options, and fixes > the bug by using $class->meta->get_all_attributes() which checks the > class heirarchy correctly.
I should be able to get out a new release with this stuff in it tomorrow or Friday evening. Thank you for figuring this out.
Subject: Re: [rt.cpan.org #58223] Inherited options do not work
Date: Mon, 14 Jun 2010 22:04:06 -0500
To: bug-MooseX-Getopt-Defanged [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
This went out this morning. Thanks again for noticing this and figuring it out.