[Moose-commits] r7726 - in Moose/trunk: lib/Moose t/050_metaclasses
doy at code2.0beta.co.uk
doy at code2.0beta.co.uk
Thu Feb 19 04:33:03 GMT 2009
Author: doy
Date: 2009-02-18 20:33:03 -0800 (Wed, 18 Feb 2009)
New Revision: 7726
Modified:
Moose/trunk/lib/Moose/Exporter.pm
Moose/trunk/t/050_metaclasses/012_moose_exporter.t
Log:
add test and docs for with_caller/as_is overriding also
Modified: Moose/trunk/lib/Moose/Exporter.pm
===================================================================
--- Moose/trunk/lib/Moose/Exporter.pm 2009-02-19 04:07:41 UTC (rev 7725)
+++ Moose/trunk/lib/Moose/Exporter.pm 2009-02-19 04:33:03 UTC (rev 7726)
@@ -459,6 +459,9 @@
This is a list of modules which contain functions that the caller
wants to export. These modules must also use C<Moose::Exporter>. The
most common use case will be to export the functions from C<Moose.pm>.
+Functions specified by C<with_caller> or C<as_is> take precedence over
+functions exported by modules specified by C<also>, so that a module
+can selectively override functions exported by another module.
C<Moose::Exporter> also makes sure all these functions get removed
when C<unimport> is called.
Modified: Moose/trunk/t/050_metaclasses/012_moose_exporter.t
===================================================================
--- Moose/trunk/t/050_metaclasses/012_moose_exporter.t 2009-02-19 04:07:41 UTC (rev 7725)
+++ Moose/trunk/t/050_metaclasses/012_moose_exporter.t 2009-02-19 04:33:03 UTC (rev 7726)
@@ -11,7 +11,7 @@
plan skip_all => 'These tests require Test::Warn 0.11';
}
else {
- plan tests => 40;
+ plan tests => 45;
}
}
@@ -239,3 +239,38 @@
'got the expected error from a reference in also to a package which does not use Moose::Exporter'
);
}
+
+{
+ package MooseX::OverridingSugar;
+
+ use Moose ();
+
+ sub has {
+ my $caller = shift;
+ return $caller . ' called has';
+ }
+
+ Moose::Exporter->setup_import_methods(
+ with_caller => ['has'],
+ also => 'Moose',
+ );
+}
+
+{
+ package WantsOverridingSugar;
+
+ MooseX::OverridingSugar->import();
+
+ ::can_ok( 'WantsOverridingSugar', 'has' );
+ ::can_ok( 'WantsOverridingSugar', 'with' );
+ ::is( has('foo'), 'WantsOverridingSugar called has',
+ 'has from MooseX::OverridingSugar is called, not has from Moose' );
+
+ MooseX::OverridingSugar->unimport();
+}
+
+{
+ ok( ! WantsSugar->can('has'), 'WantsSugar::has() has been cleaned' );
+ ok( ! WantsSugar->can('with'), 'WantsSugar::with() has been cleaned' );
+}
+
More information about the Moose-commits
mailing list