[libdist-zilla-util-configdumper-perl] 03/03: use find_attribute_by_name instead of get_attribute

Florian Schlichting fsfs at moszumanska.debian.org
Sat Nov 11 15:43:54 UTC 2017


This is an automated email from the git hooks/post-receive script.

fsfs pushed a commit to annotated tag 0.003001-source
in repository libdist-zilla-util-configdumper-perl.

commit 50b69f84a5a519d5c4235bea3d82ff3b1856c782
Author: Kent Fredric <kentfredric at gmail.com>
Date:   Thu Aug 28 10:48:37 2014 +1200

    use find_attribute_by_name instead of get_attribute
    
    this is because the former does tree traversal, but the latter does not.
    
    Thus, without this change, anything that does dumpconfig will barf as
    soon as it is extended.
---
 Changes                             |  5 +++
 lib/Dist/Zilla/Util/ConfigDumper.pm |  2 +-
 t/basic_inherit_attr.t              | 67 +++++++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/Changes b/Changes
index 59aebfd..d4b08d6 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,11 @@
 Release history for Dist-Zilla-Util-ConfigDumper
 
 {{$NEXT}}
+ [Bugfix]
+ - use instance->meta->find_attribute_by_name().
+ - because: PACKAGE-> can't be used because roles don't work
+ - because: dumpconfig( __PACKAGE__ , attrs ... ) assumes that the instance will have the attr
+ - because: $instance->get_attribute() doesn't trace inheritance.
 
 0.003000 2014-08-23T14:08:57Z
  [00 Major]
diff --git a/lib/Dist/Zilla/Util/ConfigDumper.pm b/lib/Dist/Zilla/Util/ConfigDumper.pm
index 3e766a5..7de2298 100644
--- a/lib/Dist/Zilla/Util/ConfigDumper.pm
+++ b/lib/Dist/Zilla/Util/ConfigDumper.pm
@@ -147,7 +147,7 @@ sub _mk_attribute_test {
     my ( $instance, $payload, $fails ) = @_;
     try {
       my $metaclass           = $instance->meta;
-      my $attribute_metaclass = $metaclass->get_attribute($attrname);
+      my $attribute_metaclass = $metaclass->find_attribute_by_name($attrname);
       if ( $attribute_metaclass->has_value($instance) ) {
         $payload->{$attrname} = $attribute_metaclass->get_value($instance);
       }
diff --git a/t/basic_inherit_attr.t b/t/basic_inherit_attr.t
new file mode 100644
index 0000000..3fff4a7
--- /dev/null
+++ b/t/basic_inherit_attr.t
@@ -0,0 +1,67 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::DZil qw( simple_ini );
+use Dist::Zilla::Util::Test::KENTNL 1.001 qw( dztest );
+
+# ABSTRACT: Make sure plugins do what they say they'll do
+
+require Moose;
+require Dist::Zilla::Role::Plugin;
+require Dist::Zilla::Plugin::Bootstrap::lib;
+require Dist::Zilla::Plugin::GatherDir;
+require Dist::Zilla::Plugin::MetaConfig;
+
+my $t   = dztest();
+my $pn  = 'TestPlugin';
+my $fpn = 'Dist::Zilla::Plugin::' . $pn;
+
+$t->add_file( 'dist.ini', simple_ini( ['Bootstrap::lib'], ['GatherDir'], ['MetaConfig'], [$pn], ) );
+$t->add_file( 'lib/Dist/Zilla/Plugin/BasePlugin.pm', <<"EOREOR" );
+package #
+  Dist::Zilla::Plugin::BasePlugin;
+
+use Moose qw( has around with );
+use Dist::Zilla::Util::ConfigDumper qw( config_dumper );
+with 'Dist::Zilla::Role::Plugin';
+
+has 'lattr' => ( is => 'ro', 'lazy' => 1, default => sub { 'I have value, my life has meaning' } );
+has 'attr' => ( is => 'ro', default => sub { 'I have value, my life has meaning' } );
+
+around dump_config => config_dumper(__PACKAGE__, { attrs => [qw( attr )] });
+
+no Moose;
+1;
+EOREOR
+
+$t->add_file( 'lib/Dist/Zilla/Plugin/' . $pn . '.pm', <<"EOF");
+package $fpn;
+
+use Moose qw( has around extends );
+use Dist::Zilla::Util::ConfigDumper qw( config_dumper );
+extends 'Dist::Zilla::Plugin::BasePlugin';
+
+has 'childattr' => ( is => 'ro', default => sub { 'Rainbows and lollypops, etc' } );
+
+around dump_config => config_dumper(__PACKAGE__, { attrs => [qw( childattr )] });
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
+EOF
+
+$t->build_ok;
+$t->meta_path_deeply(
+  '/x_Dist_Zilla/plugins/*/*[ key eq \'class\' and value eq \'Dist::Zilla::Plugin::TestPlugin\' ]/../*[ key eq \'config\']',
+  [
+    {
+      'Dist::Zilla::Plugin::TestPlugin' => { 'childattr' => 'Rainbows and lollypops, etc' },
+      'Dist::Zilla::Plugin::BasePlugin' => { 'attr'      => 'I have value, my life has meaning' },
+    }
+  ],
+  "Plugin list expected"
+);
+done_testing;
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libdist-zilla-util-configdumper-perl.git



More information about the Pkg-perl-cvs-commits mailing list