X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FClass%2FMOP.pm;h=be88dc7888a7f6332167ba029df0fcd082dee849;hb=8ee74136c5d5c5a6416844e7238898f47b00f553;hp=98228e8db4acce5bed5b3d0acc80e816b7b0f618;hpb=544143b2f61cc67252810d54e8dc595738d9cd41;p=gitmo%2FClass-MOP.git diff --git a/lib/Class/MOP.pm b/lib/Class/MOP.pm index 98228e8..be88dc7 100644 --- a/lib/Class/MOP.pm +++ b/lib/Class/MOP.pm @@ -13,8 +13,23 @@ use Class::MOP::Method; use Class::MOP::Immutable; -our $VERSION = '0.44'; -our $AUTHORITY = 'cpan:STEVAN'; +BEGIN { + our $VERSION = '0.53'; + our $AUTHORITY = 'cpan:STEVAN'; + + use XSLoader; + 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 }; + } +} { # Metaclasses are singletons, so we cache them here. @@ -59,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; } @@ -120,9 +135,7 @@ Class::MOP::Package->meta->add_attribute( # rather than re-produce it here 'namespace' => \&Class::MOP::Package::namespace }, - # NOTE: - # protect this from silliness - init_arg => '!............( DO NOT DO THIS )............!', + init_arg => undef, default => sub { \undef } )) ); @@ -157,9 +170,7 @@ Class::MOP::Module->meta->add_attribute( # rather than re-produce it here 'version' => \&Class::MOP::Module::version }, - # NOTE: - # protect this from silliness - init_arg => '!............( DO NOT DO THIS )............!', + init_arg => undef, default => sub { \undef } )) ); @@ -178,9 +189,7 @@ Class::MOP::Module->meta->add_attribute( # rather than re-produce it here 'authority' => \&Class::MOP::Module::authority }, - # NOTE: - # protect this from silliness - init_arg => '!............( DO NOT DO THIS )............!', + init_arg => undef, default => sub { \undef } )) ); @@ -225,9 +234,7 @@ Class::MOP::Class->meta->add_attribute( # rather than re-produce it here 'superclasses' => \&Class::MOP::Class::superclasses }, - # NOTE: - # protect this from silliness - init_arg => '!............( DO NOT DO THIS )............!', + init_arg => undef, default => sub { \undef } )) ); @@ -330,6 +337,14 @@ Class::MOP::Attribute->meta->add_attribute( ); Class::MOP::Attribute->meta->add_attribute( + Class::MOP::Attribute->new('$!initializer' => ( + init_arg => 'initializer', + reader => { 'initializer' => \&Class::MOP::Attribute::initializer }, + predicate => { 'has_initializer' => \&Class::MOP::Attribute::has_initializer }, + )) +); + +Class::MOP::Attribute->meta->add_attribute( Class::MOP::Attribute->new('$!writer' => ( init_arg => 'writer', reader => { 'writer' => \&Class::MOP::Attribute::writer }, @@ -714,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 @@ -732,6 +759,10 @@ NOTE: This does a basic check of the symbol table to try and determine as best it can if the C<$class_name> is loaded, it is probably correct about 99% of the time. +=item B + +=item B + =back =head2 Metaclass cache functions @@ -881,9 +912,11 @@ Rob (robkinyon) Kinyon Yuval (nothingmuch) Kogman +Scott (konobi) McWhirter + =head1 COPYRIGHT AND LICENSE -Copyright 2006, 2007 by Infinity Interactive, Inc. +Copyright 2006-2008 by Infinity Interactive, Inc. L