Object::Lazy::Ref - Simulation of C<ref $object> for Object::Lazy


Object-Lazy documentation Contained in the Object-Lazy distribution.

Index


Code Index:

NAME

Top

Object::Lazy::Ref - Simulation of ref $object for Object::Lazy

VERSION

Top

0.01

SYNOPSIS

Top

    use Object::Lazy::Ref;

    Object::Lazy::Ref::register($object);

DESCRIPTION

Top

Simulation of ref $obj for Object::Lazy

SUBROUTINES/METHODS

Top

sub register

switch on the simulation.

    Object::Lazy::Ref::register($object);

DIAGNOSTICS

Top

nothing

CONFIGURATION AND ENVIRONMENT

Top

nothing

DEPENDENCIES

Top

nothing

INCOMPATIBILITIES

Top

This module will change *CORE::GLOBAL::ref premanently. If a call of sub ref not matched with an registered Object::Lazy object the *CORE::GLOBAL::ref will be restored during call and will fall back after that.

When another programm decided to change *CORE::GLOBAL::ref permanently it has to fallback to the old *CORE::GLOBAL::ref too. This is than the Object::Lazy one. When it bails out to CORE::ref, the pipe is broken.

BUGS AND LIMITATIONS

Top

not known

AUTHOR

Top

Steffen Winkler

LICENSE AND COPYRIGHT

Top


Object-Lazy documentation Contained in the Object-Lazy distribution.

package Object::Lazy::Ref;

use strict;
use warnings;

our $VERSION = '0.01';

use Carp qw(croak);

my %register;

BEGIN {
    my $old_core_global_ref = *CORE::GLOBAL::ref;
    *CORE::GLOBAL::ref = sub ($) {
        my $ref = shift;

        return
            exists $register{$ref}
            ? $register{$ref}
            : do {
                local *CORE::GLOBAL::ref = $old_core_global_ref;
                ref $ref;
            };
    }
}

sub register {
    my $object = shift;

    $register{$object} = $object->{ref};

    return;
}

# $Id$

1;

__END__