[libmoosex-lazyrequire-perl] 01/03: make this module work with attrs in roles with Moose 2
Intrigeri
intrigeri at moszumanska.debian.org
Wed Aug 27 21:25:19 UTC 2014
This is an automated email from the git hooks/post-receive script.
intrigeri pushed a commit to annotated tag 0.07
in repository libmoosex-lazyrequire-perl.
commit 362ed436d4d4738633848c14c1fc7b88766b621c
Author: Dave Rolsky <autarch at urth.org>
Date: Sun Apr 3 13:41:19 2011 -0500
make this module work with attrs in roles with Moose 2
---
Changes | 3 +++
lib/MooseX/LazyRequire.pm | 14 ++++++++++++--
t/basic.t | 48 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/Changes b/Changes
index c0e775e..23dee1d 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,6 @@
+ * Allow this module to be used with attributes in roles when using Moose
+ 1.9900+ (Dave Rolsky).
+
0.06 Mon, 19 Jul 2010 05:19:42 +0200
* Updated to avoid warnings from Moose 1.09 (Dave Rolsky).
diff --git a/lib/MooseX/LazyRequire.pm b/lib/MooseX/LazyRequire.pm
index 57551b1..9ce2b2b 100644
--- a/lib/MooseX/LazyRequire.pm
+++ b/lib/MooseX/LazyRequire.pm
@@ -40,7 +40,7 @@ parameter or through a writer method.
=head1 CAVEATS
-Apparently Moose roles don't have an attribute metaclass, so this module can't
+Prior to Moose 1.9900, roles didn't have an attribute metaclass, so this module can't
easily apply its magic to attributes defined in roles. If you want to use
C<lazy_required> in role attributes, you'll have to apply the attribute trait
yourself:
@@ -51,14 +51,24 @@ yourself:
lazy_required => 1,
);
+With Moose 1.9900, you can use this module in roles just the same way you can
+in classes.
+
=cut
-Moose::Exporter->setup_import_methods(
+my %metaroles = (
class_metaroles => {
attribute => [LazyRequire],
},
);
+$metaroles{role_metaroles} = {
+ applied_attribute => [LazyRequire],
+ }
+ if $Moose::VERSION >= 1.9900;
+
+Moose::Exporter->setup_import_methods(%metaroles);
+
1;
=begin Pod::Coverage
diff --git a/t/basic.t b/t/basic.t
index 14fb9a0..7947040 100644
--- a/t/basic.t
+++ b/t/basic.t
@@ -77,4 +77,52 @@ throws_ok(sub {
is($baz, 43);
}
+SKIP:
+{
+ skip 'These tests require Moose 1.9900+', 3
+ unless $Moose::VERSION >= 1.9900;
+
+{
+ package Role;
+ use Moose::Role;
+ use MooseX::LazyRequire;
+
+ has foo => (
+ is => 'rw',
+ lazy_required => 1,
+ );
+
+ has baz => (
+ is => 'ro',
+ lazy => 1,
+ builder => '_build_baz',
+ );
+
+ sub _build_baz { shift->foo + 1 }
+}
+
+{
+ package Quux;
+ use Moose;
+ with 'Role';
+}
+
+{
+ my $bar = Quux->new;
+
+ throws_ok(sub {
+ $bar->baz;
+ }, qr/must be provided/);
+
+ $bar->foo(42);
+
+ my $baz;
+ lives_ok(sub {
+ $baz = $bar->baz;
+ });
+
+ is($baz, 43);
+}
+}
+
done_testing;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmoosex-lazyrequire-perl.git
More information about the Pkg-perl-cvs-commits
mailing list