convert the rest of the simple readers in cmop to xs
[gitmo/Class-MOP.git] / lib / Class / MOP / Attribute.pm
index ead19fc..d0cf234 100644 (file)
@@ -10,7 +10,7 @@ use Carp         'confess';
 use Scalar::Util 'blessed', 'weaken';
 use Try::Tiny;
 
-our $VERSION   = '0.97';
+our $VERSION   = '1.11';
 $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
@@ -73,7 +73,9 @@ sub _new {
         'clearer'            => $options->{clearer},
         'builder'            => $options->{builder},
         'init_arg'           => $options->{init_arg},
-        'default'            => $options->{default},
+        exists $options->{default}
+            ? ('default'     => $options->{default})
+            : (),
         'initializer'        => $options->{initializer},
         'definition_context' => $options->{definition_context},
         # keep a weakened link to the
@@ -117,7 +119,7 @@ sub initialize_instance_slot {
             $params->{$init_arg},
         );
     } 
-    elsif (defined $self->{'default'}) {
+    elsif (exists $self->{'default'}) {
         $self->_set_initial_slot_value(
             $meta_instance, 
             $instance,
@@ -156,9 +158,6 @@ sub _set_initial_slot_value {
     $instance->$initializer($value, $callback, $self);
 }
 
-sub associated_class   { $_[0]->{'associated_class'}   }
-sub associated_methods { $_[0]->{'associated_methods'} }
-
 sub get_read_method  { 
     my $self   = shift;    
     my $reader = $self->reader || $self->accessor;
@@ -402,6 +401,40 @@ sub install_accessors {
 
 }
 
+sub inline_get {
+    my $self = shift;
+    my ($instance) = @_;
+
+    return $self->associated_class->get_meta_instance->inline_get_slot_value(
+        $instance, $self->name );
+}
+
+sub inline_set {
+    my $self = shift;
+    my ( $instance, $value ) = @_;
+
+    return $self->associated_class->get_meta_instance->inline_set_slot_value(
+        $instance, $self->name, $value );
+}
+
+sub inline_has {
+    my $self = shift;
+    my ($instance) = @_;
+
+    return
+        $self->associated_class->get_meta_instance
+        ->inline_is_slot_initialized( $instance, $self->name );
+}
+
+sub inline_clear {
+    my $self = shift;
+    my ($instance) = @_;
+
+    return
+        $self->associated_class->get_meta_instance
+        ->inline_deinitialize_slot( $instance, $self->name );
+}
+
 1;
 
 __END__
@@ -798,7 +831,7 @@ called when the instance is first being initialized.
 Returns the value without going through the accessor. Note that this
 works even with write-only accessors.
 
-=item B<< $sttr->get_raw_value($instance) >>
+=item B<< $attr->get_raw_value($instance) >>
 
 Returns the value without any side effects such as lazy attributes.
 
@@ -892,6 +925,18 @@ attribute.
 This does not currently remove methods from the list returned by
 C<associated_methods>.
 
+=item B<< $attr->inline_get >>
+
+=item B<< $attr->inline_set >>
+
+=item B<< $attr->inline_has >>
+
+=item B<< $attr->inline_clear >>
+
+These methods return a code snippet suitable for inlining the relevant
+operation. They expect strings containing variable names to be used in the
+inlining, like C<'$self'> or C<'$_[1]'>.
+
 =back
 
 =head2 Introspection
@@ -914,7 +959,7 @@ Stevan Little E<lt>stevan@iinteractive.comE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2006-2009 by Infinity Interactive, Inc.
+Copyright 2006-2010 by Infinity Interactive, Inc.
 
 L<http://www.iinteractive.com>