| MooseX-GlobRef documentation | Contained in the MooseX-GlobRef distribution. |
MooseX::GlobRef::Role::Meta::Instance - Instance metaclass for MooseX::GlobRef
Moose::Util::MetaRole::apply_metaclass_roles(
for_class => $caller,
instance_metaclass_roles =>
[ 'MooseX::GlobRef::Role::Meta::Instance' ],
);
This instance metaclass allows to store Moose object in glob reference of file handle. It is applied by MooseX::GlobRef.
The methods overridden by this class.
Piotr Roszatycki <dexter@cpan.org>
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.
| 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;