From: Brandon L Black Date: Tue, 10 Jun 2008 02:32:15 +0000 (+0000) Subject: stop the redefine warnings? X-Git-Tag: 0.21~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ed5a217268b1f8b54cc4fff97d8e8a2a0f17f00b;p=gitmo%2FClass-C3.git stop the redefine warnings? --- diff --git a/README b/README index 00290fb..d9184f5 100644 --- a/README +++ b/README @@ -28,16 +28,16 @@ SYNOPSIS # package main; - - # initializez the C3 module + + # initializez the C3 module # (formerly called in INIT) Class::C3::initialize(); print join ', ' => Class::C3::calculateMRO('Diamond_D') # prints D, B, C, A print D->hello() # prints 'C::hello' instead of the standard p5 'A::hello' - - D->can('hello')->(); # can() also works correctly + + D->can('hello')->(); # can() also works correctly UNIVERSAL::can('D', 'hello'); # as does UNIVERSAL::can() DESCRIPTION @@ -95,12 +95,12 @@ OPTIONAL LOWERCASE PRAGMA package MyClass; use c3; - + The the more clunky: package MyClass; use Class::C3; - + But hey, it's your choice, thats why it is optional. FUNCTIONS @@ -117,15 +117,15 @@ FUNCTIONS package Foo; use Class::C3; # ... Foo methods here - - package Bar; + + package Bar; use Class::C3; use base 'Foo'; # ... Bar methods here - - package main; - - Class::C3::initialize(); # now it is safe to use Foo and Bar + + package main; + + Class::C3::initialize(); # now it is safe to use Foo and Bar This function used to be called automatically for you in the INIT phase of the perl compiler, but that lead to warnings if this module @@ -161,27 +161,27 @@ METHOD REDISPATCHING \ / - - package A; + + package A; use c3; sub foo { 'A::foo' } - - package B; + + package B; use base 'A'; use c3; sub foo { 'B::foo => ' . (shift)->next::method() } - - package B; + + package B; use base 'A'; use c3; sub foo { 'C::foo => ' . (shift)->next::method() } - - package D; + + package D; use base ('B', 'C'); use c3; sub foo { 'D::foo => ' . (shift)->next::method() } - - print D->foo; # prints out "D::foo => B::foo => C::foo => A::foo" + + print D->foo; # prints out "D::foo => B::foo => C::foo => A::foo" A few things to note. First, we do not require you to add on the method name to the "next::method" call (this is unlike "NEXT::" and "SUPER::" @@ -196,7 +196,7 @@ METHOD REDISPATCHING it will throw an exception. You can use "next::can" to see if "next::method" will succeed before you call it like so: - $self->next::method(@_) if $self->next::can; + $self->next::method(@_) if $self->next::can; Additionally, you can use "maybe::next::method" as a shortcut to only call the next method if it exists. The previous example could be simply diff --git a/lib/Class/C3.pm b/lib/Class/C3.pm index 2c1d336..8b4e75a 100644 --- a/lib/Class/C3.pm +++ b/lib/Class/C3.pm @@ -67,6 +67,11 @@ sub import { ## initializers +# This prevents silly warnings when Class::C3 is +# used explicitly along with MRO::Compat under 5.9.5+ + +{ no warnings 'redefine'; + sub initialize { %next::METHOD_CACHE = (); # why bother if we don't have anything ... @@ -100,6 +105,8 @@ sub uninitialize { sub reinitialize { goto &initialize } +} # end of "no warnings 'redefine'" + ## functions for applying C3 to classes sub _calculate_method_dispatch_tables {