From: Stevan Little Date: Wed, 9 Jan 2008 17:39:22 +0000 (+0000) Subject: adding the 5.10 constant to allow us to use those features X-Git-Tag: 0_51~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c1d5345a2dedc909590256182a1e77ea5f1566ef;p=gitmo%2FClass-MOP.git adding the 5.10 constant to allow us to use those features --- diff --git a/Changes b/Changes index 0eaf9d9..443b576 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,21 @@ Revision history for Perl extension Class-MOP. 0.51 ~~~ some misc. doc. fixes ~~~ ~~ updated copyright dates ~~ + + * Class::MOP + - now sets the IS_RUNNING_ON_5_10 + constant so that we can take advantage + of some of the nice bits of 5.10 + + * Class::MOP::Class + - uses the IS_RUNNING_ON_5_10 flag to + optimize the &linearized_isa method + and avoid the hack/check for circular + inheritence in &class_precedence_list + + * Class::MOP::Immutable + - the immutable class now keeps track of + the transformer which immutablized it 0.50 Fri. Dec. 21, 2007 * Class::MOP::Class diff --git a/lib/Class/MOP.pm b/lib/Class/MOP.pm index cfb9503..8ca431d 100644 --- a/lib/Class/MOP.pm +++ b/lib/Class/MOP.pm @@ -21,8 +21,13 @@ BEGIN { XSLoader::load( 'Class::MOP', $VERSION ); unless ($] < 5.009_005) { + require mro; no warnings 'redefine', 'prototype'; *check_package_cache_flag = \&mro::get_pkg_gen; + *IS_RUNNING_ON_5_10 = sub () { 1 }; + } + else { + *IS_RUNNING_ON_5_10 = sub () { 0 }; } } @@ -69,14 +74,14 @@ sub load_class { } sub is_class_loaded { - my $class = shift; - no strict 'refs'; - return 1 if defined ${"${class}::VERSION"} || defined @{"${class}::ISA"}; - foreach (keys %{"${class}::"}) { - next if substr($_, -2, 2) eq '::'; - return 1 if defined &{"${class}::$_"}; - } - return 0; + my $class = shift; + no strict 'refs'; + return 1 if defined ${"${class}::VERSION"} || defined @{"${class}::ISA"}; + foreach (keys %{"${class}::"}) { + next if substr($_, -2, 2) eq '::'; + return 1 if defined &{"${class}::$_"}; + } + return 0; } @@ -724,6 +729,18 @@ See L for more details. =head1 FUNCTIONS +=head2 Constants + +=over 4 + +=item I + +We set this constant depending on what version perl we are on, this +allows us to take advantage of new 5.10 features and stay backwards +compat. + +=back + =head2 Utility functions =over 4 diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index e50ee9a..a6f9210 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -12,7 +12,7 @@ use Carp 'confess'; use Scalar::Util 'blessed', 'reftype', 'weaken'; use Sub::Name 'subname'; -our $VERSION = '0.25'; +our $VERSION = '0.26'; our $AUTHORITY = 'cpan:STEVAN'; use base 'Class::MOP::Module'; @@ -423,7 +423,7 @@ sub subclasses { my $symbol_table_hashref = do { no strict 'refs'; \%{"${outer_class}::"} }; - SYMBOL: + SYMBOL: for my $symbol ( keys %$symbol_table_hashref ) { next SYMBOL if $symbol !~ /\A (\w+):: \z/x; my $inner_class = $1; @@ -457,18 +457,28 @@ sub subclasses { sub linearized_isa { - my %seen; - grep { !($seen{$_}++) } (shift)->class_precedence_list + if (Class::MOP::IS_RUNNING_ON_5_10()) { + return @{ mro::get_linear_isa( (shift)->name ) }; + } + else { + my %seen; + return grep { !($seen{$_}++) } (shift)->class_precedence_list; + } } sub class_precedence_list { my $self = shift; - # NOTE: - # We need to check for circular inheritance here. - # This will do nothing if all is well, and blow - # up otherwise. Yes, it's an ugly hack, better - # suggestions are welcome. - { ($self->name || return)->isa('This is a test for circular inheritance') } + + unless (Class::MOP::IS_RUNNING_ON_5_10()) { + # NOTE: + # We need to check for circular inheritance here + # if we are are not on 5.10, cause 5.8 detects it + # late. This will do nothing if all is well, and + # blow up otherwise. Yes, it's an ugly hack, better + # suggestions are welcome. + # - SL + ($self->name || return)->isa('This is a test for circular inheritance') + } ( $self->name, diff --git a/lib/Class/MOP/Immutable.pm b/lib/Class/MOP/Immutable.pm index bc521da..aabb62b 100644 --- a/lib/Class/MOP/Immutable.pm +++ b/lib/Class/MOP/Immutable.pm @@ -9,7 +9,7 @@ use Class::MOP::Method::Constructor; use Carp 'confess'; use Scalar::Util 'blessed'; -our $VERSION = '0.03'; +our $VERSION = '0.04'; our $AUTHORITY = 'cpan:STEVAN'; sub new {