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'
+);