Acme-Class-Std

 view release on metacpan or  search on metacpan

Std.pm  view on Meta::CPAN

package Acme::Class::Std;

use strict;

require Exporter;
use Class::Std();

use vars qw($VERSION);
*ISA = \*Class::Std::ISA;
*EXPORT = \*Class::Std::EXPORT;
*EXPORT_OK = \*Class::Std::EXPORT_OK;
*EXPORT_TAGS = \*Class::Std::EXPORT_TAGS;

$VERSION = '0.01';

my $count = "ACME";
my %enhanced;
my $all = 0;

sub import {
  $enhanced{+caller}++;
  goto &Class::Std::import;
}

sub ID ($) {
  my ($package, undef, undef, $sub) = caller 1;
  if ($sub eq 'Class::Std::new' && $_[0]->isa('SCALAR')
      && ($all || $enhanced{ref $_[0]})) {
    # Strangely, it seems that one can dup an unopened file handle without
    # warnings.
    eval "open $count, '<&dead'";
    my $ref = *{delete $Acme::Class::Std::{$count++}}{IO};
    $_[0] = bless $ref, ref $_[0];
  }
  goto &Scalar::Util::refaddr;
}

{
  local $^W;
  *Class::Std::ID = \&ID;
}

__END__

=head1 NAME

Acme::Class::Std - "Enhances" Class::Std;

=head1 SYNOPSIS

  package Jugarum;
  use Acme::Class::Std;
  package main;
  my $obj = Jugarum->new; # Can't accidentally be serialised.

=head1 DESCRIPTION

Class::Std's inside out objects are wonderful, but all the common
serialisation packages assume that because they can see inside them, they
can successfully serialise your object. Wrong! Because all they serialise
is the ID, you may suffer data loss without realising.

Acme::Class::Std shows those pesky serialise modules just who is boss. They
can go peeking and prodding, but they will get their fingers burnt:

=over

=item Data::Dumper

    package Kakroosh;
    use Acme::Class::Std;
    package main;
    $o = Foo->new;
    use Data::Dumper;
    print Dumper $o;

    cannot handle ref type 15 at /usr/local/lib/perl5/5.8.8/i386-freebsd/Data/Dumper.pm line 179.
    $VAR1 = bless( , 'Foo' );

=item Storable

    package Kakroosh;
    use Acme::Class::Std;
    package main;
    $o = Foo->new;
    use Storable;
    my $f = Storable::freeze $o;

    Can't store IO items at ../../lib/Storable.pm (autosplit into ../../lib/auto/Storable/_freeze.al) line 290, at -e line 1

=item YAML



( run in 0.641 second using v1.01-cache-2.11-cpan-ceb78f64989 )