MooseX::GlobRef::Role::Meta::Instance - Instance metaclass for MooseX::GlobRef


MooseX-GlobRef documentation Contained in the MooseX-GlobRef distribution.

Index


Code Index:

NAME

Top

MooseX::GlobRef::Role::Meta::Instance - Instance metaclass for MooseX::GlobRef

SYNOPSIS

Top

  Moose::Util::MetaRole::apply_metaclass_roles(
      for_class => $caller,
      instance_metaclass_roles =>
          [ 'MooseX::GlobRef::Role::Meta::Instance' ],
  );

DESCRIPTION

Top

This instance metaclass allows to store Moose object in glob reference of file handle. It is applied by MooseX::GlobRef.

METHODS

Top

<<override>> create_instance() : Object
<<override>> clone_instance( instance : Object ) : Object
<<override>> get_slot_value( instance : Object, slot_name : Str ) : Any
<<override>> set_slot_value( instance : Object, slot_name : Str, value : Any ) : Any
<<override>> deinitialize_slot( instance : Object, slot_name : Str ) : Any
<<override>> is_slot_initialized( instance : Object, slot_name : Str ) : Bool
<<override>> weaken_slot_value( instance : Object, slot_name : Str )
<<override>> inline_create_instance( class_variable : Str ) : Str
<<override>> inline_slot_access( instance_variable : Str, slot_name : Str ) : Str

The methods overridden by this class.

SEE ALSO

Top

MooseX::GlobRef, Moose::Meta::Instance, Moose.

AUTHOR

Top

Piotr Roszatycki <dexter@cpan.org>

LICENSE

Top

Copyright (c) 2007, 2008, 2009, 2010 Piotr Roszatycki <dexter@cpan.org>.

This is free software; you can redistribute it and/or modify it under the same terms as perl itself.

See http://dev.perl.org/licenses/artistic.html


MooseX-GlobRef documentation Contained in the MooseX-GlobRef distribution.
#!/usr/bin/perl -c

package MooseX::GlobRef::Role::Meta::Instance;

use 5.006;
use strict;
use warnings;

our $VERSION = '0.0701';

use Moose::Role;


# Use weaken
use Scalar::Util ();


override 'create_instance' => sub {
    my ($self) = @_;

    # create anonymous file handle
    select select my $fh;

    # initialize hash slot of file handle
    %{*$fh} = ();

    return bless $fh => $self->_class_name;
};


override 'clone_instance' => sub {
    my ($self, $instance) = @_;

    # create anonymous file handle
    select select my $fh;

    # initialize hash slot of file handle
    %{*$fh} = ( %{*$instance} );

    return bless $fh => $self->_class_name;
};

override 'get_slot_value' => sub {
    my ($self, $instance, $slot_name) = @_;
    return *$instance->{$slot_name};
};


override 'set_slot_value' => sub {
    my ($self, $instance, $slot_name, $value) = @_;
    return *$instance->{$slot_name} = $value;
};


override 'deinitialize_slot' => sub {
    my ($self, $instance, $slot_name) = @_;
    return delete *$instance->{$slot_name};
};


override 'is_slot_initialized' => sub {
    my ($self, $instance, $slot_name) = @_;
    return exists *$instance->{$slot_name};
};


override 'weaken_slot_value' => sub {
    my ($self, $instance, $slot_name) = @_;
    return Scalar::Util::weaken *$instance->{$slot_name};
};


override 'inline_create_instance' => sub {
    my ($self, $class_variable) = @_;
    return 'do { select select my $fh; %{*$fh} = (); bless $fh => ' . $class_variable . ' }';
};


override 'inline_slot_access' => sub {
    my ($self, $instance_variable, $slot_name) = @_;
    return '*{' . $instance_variable . '}->{' . $slot_name . '}';
};


no Moose::Role;

1;