Acme::Curse - Remove the blessing that lay on references


Acme-Curse documentation Contained in the Acme-Curse distribution.

Index


Code Index:

NAME

Top

Acme::Curse - Remove the blessing that lay on references

SYNOPSIS

Top

    use Acme::Curse qw(curse);

    my $unblessed_ref = curse($object);

DESCRIPTION

Top

Did you ever want to droo the blessing of an object? Well, now you can: Acme::Curse unblesses reference by returning a shallow, non-blessed copy of the object.

Currently only references to scalar, hashes, arrays and code objects can be unblessed.

Exported subs:

curse

Unblesses a reference to an object.

BUGS

Top

None known, but surely there are many.

AUTHOR

Top

Moritz Lenz, http://perlgeek.de/, http://perl-6.de/

LICENSE AND COPYRIGHT

Top


Acme-Curse documentation Contained in the Acme-Curse distribution.

package Acme::Curse;

use strict;
use warnings;
use Exporter qw(import);
use Scalar::Util qw(reftype);

our @EXPORT_OK = qw(curse);

sub curse {
    my ($obj) = @_;
    my $type = reftype($obj);
    if ($type eq 'HASH') {
        return { %$obj };
    } 
    elsif ($type eq 'ARRAY') {
        return [ @$obj ];
    } elsif ($type eq 'SCALAR'){
        my $copy = $$obj;
        return \$copy;
    }
    elsif ($type eq 'CODE') {
        return sub { goto &$obj };
    }
    else {
        die "Don't know how to curse ${type}s";
    }
}

1;