svn merge -r 3569:3574 branches/Class-MOP-initializer/ trunk/
[gitmo/Class-MOP.git] / lib / Class / MOP.pm
index 4c18e4c..b5ecac0 100644 (file)
@@ -13,11 +13,23 @@ use Class::MOP::Method;
 
 use Class::MOP::Immutable;
 
-our $VERSION   = '0.49';
-our $AUTHORITY = 'cpan:STEVAN';
-
-use XSLoader;
-XSLoader::load( 'Class::MOP', $VERSION );
+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.
@@ -62,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;
 }
 
 
@@ -123,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 }
     ))
 );
@@ -160,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 }
     ))
 );
@@ -181,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 }
     ))
 );
@@ -228,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 }
     ))
 );
@@ -333,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     },
@@ -717,6 +729,18 @@ See L<Class::MOP::Method> for more details.
 
 =head1 FUNCTIONS
 
+=head2 Constants
+
+=over 4
+
+=item I<IS_RUNNING_ON_5_10>
+
+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
@@ -735,7 +759,7 @@ 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<check_package_cache_flag>
+=item B<check_package_cache_flag ($pkg)>
 
 =item B<get_code_info ($code)>
 
@@ -888,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<http://www.iinteractive.com>