From: Jesse Luehrs Date: Thu, 19 Feb 2009 04:33:03 +0000 (+0000) Subject: add test and docs for with_caller/as_is overriding also X-Git-Tag: 0.71~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ae8817b61e2ad2ee7ebfee3d34ee5374f3c21396;p=gitmo%2FMoose.git add test and docs for with_caller/as_is overriding also --- diff --git a/lib/Moose/Exporter.pm b/lib/Moose/Exporter.pm index beb561c..b63003b 100644 --- a/lib/Moose/Exporter.pm +++ b/lib/Moose/Exporter.pm @@ -459,6 +459,9 @@ themselves, and therefore wants to keep it. This is a list of modules which contain functions that the caller wants to export. These modules must also use C. The most common use case will be to export the functions from C. +Functions specified by C or C take precedence over +functions exported by modules specified by C, so that a module +can selectively override functions exported by another module. C also makes sure all these functions get removed when C is called. diff --git a/t/050_metaclasses/012_moose_exporter.t b/t/050_metaclasses/012_moose_exporter.t index 5bc4115..0389fd4 100644 --- a/t/050_metaclasses/012_moose_exporter.t +++ b/t/050_metaclasses/012_moose_exporter.t @@ -11,7 +11,7 @@ BEGIN { plan skip_all => 'These tests require Test::Warn 0.11'; } else { - plan tests => 40; + plan tests => 45; } } @@ -239,3 +239,38 @@ BEGIN { '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' ); +} +