[libdist-zilla-util-configdumper-perl] 03/03: Dont cache metaclass from the role, call it on the instance instead, because role metaclasses have useless metaattributes"

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


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

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

commit 83f1bae43c82acc61babf4f16898c09f9a808675
Author: Kent Fredric <kentfredric at gmail.com>
Date:   Sat Aug 23 06:37:11 2014 +1200

    Dont cache metaclass from the role, call it on the instance instead, because role metaclasses have useless metaattributes"
---
 Changes                             |  3 ++
 lib/Dist/Zilla/Util/ConfigDumper.pm |  6 ++--
 t/basic_role_attr.t                 | 66 +++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 3 deletions(-)

diff --git a/Changes b/Changes
index 80d9b86..b778428 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,9 @@
 Release history for Dist-Zilla-Util-ConfigDumper
 
 {{$NEXT}}
+ [Bugfix]
+ - Seems Roles don't like ->meta->get_attribute being used for anything, so early attribute sanity checking options
+   were misguided.
 
 0.002000 2014-08-22T17:52:30Z
  [00 Major]
diff --git a/lib/Dist/Zilla/Util/ConfigDumper.pm b/lib/Dist/Zilla/Util/ConfigDumper.pm
index b9a3966..972fbe4 100644
--- a/lib/Dist/Zilla/Util/ConfigDumper.pm
+++ b/lib/Dist/Zilla/Util/ConfigDumper.pm
@@ -52,12 +52,12 @@ sub _mk_method_test {
 }
 
 sub _mk_attribute_test {
-  my ( $package, $attrname ) = @_;
-  my $metaclass           = $package->meta;
-  my $attribute_metaclass = $metaclass->get_attribute($attrname);
+  my ( undef, $attrname ) = @_;
   return sub {
     my ( $instance, $payload, $fails ) = @_;
     try {
+      my $metaclass           = $instance->meta;
+      my $attribute_metaclass = $metaclass->get_attribute($attrname);
       if ( $attribute_metaclass->has_value($instance) ) {
         $payload->{$attrname} = $attribute_metaclass->get_value($instance);
       }
diff --git a/t/basic_role_attr.t b/t/basic_role_attr.t
new file mode 100644
index 0000000..06730ef
--- /dev/null
+++ b/t/basic_role_attr.t
@@ -0,0 +1,66 @@
+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/Role/TestRole.pm', <<"EOREOR" );
+package #
+  Dist::Zilla::Role::TestRole;
+
+use Moose::Role qw( has around with );
+use Dist::Zilla::Util::ConfigDumper qw( config_dumper );
+with 'Dist::Zilla::Role::Plugin';
+
+has 'attr' => ( is => 'ro', 'lazy' => 1, 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 with );
+use Dist::Zilla::Util::ConfigDumper qw( config_dumper );
+with 'Dist::Zilla::Role::TestRole';
+
+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::Role::TestRole'     => {},
+    }
+  ],
+  "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