File: MyOtherFreezer.pm

package info (click to toggle)
libpoe-perl 2%3A0.19-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,376 kB
  • ctags: 1,294
  • sloc: perl: 18,032; makefile: 43
file content (44 lines) | stat: -rw-r--r-- 950 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# $Id: MyOtherFreezer.pm,v 1.3 2002/01/10 20:39:45 rcaputo Exp $
# A sample external freezer for POE::Filter::Reference testing.

package MyOtherFreezer;

use strict;

use vars qw($VERSION);
$VERSION = (qw($Revision: 1.3 $ ))[1];

sub new {
  my $type = shift;
  return bless [ ], $type;
}

sub freeze {
  my $thing = shift;
  $thing = shift if ref($thing) eq 'MyOtherFreezer';

  if (ref($thing) eq 'SCALAR') {
    return reverse(join "\0", ref($thing), $$thing);
  }
  elsif (ref($thing) eq 'Package') {
    return reverse(join "\0", ref($thing), @$thing);
  }
  die "can't freeze things of type ", ref($thing);
}

sub thaw {
  my $thing = shift;
  $thing = shift if ref($thing) eq 'MyOtherFreezer';

  my ($type, @stuff) = split /\0/, reverse($thing);
  if ($type eq 'SCALAR') {
    my $scalar = $stuff[0];
    return \$scalar;
  }
  elsif ($type eq 'Package') {
    return bless \@stuff, $type;
  }
  die "can't thaw things of type $type";
}

1;