1 |
joko |
1.1 |
## ------------------------------------------------------------------------- |
2 |
|
|
## $Id: Exception.pm,v 1.2 2003/02/20 20:53:55 joko Exp $ |
3 |
|
|
## ------------------------------------------------------------------------- |
4 |
|
|
## $Log: Exception.pm,v $ |
5 |
|
|
## ------------------------------------------------------------------------- |
6 |
|
|
|
7 |
|
|
|
8 |
|
|
package Hash::Serializer; |
9 |
|
|
|
10 |
|
|
use strict; |
11 |
|
|
use warnings; |
12 |
|
|
|
13 |
|
|
use overload |
14 |
|
|
'""' => \&stringify, |
15 |
|
|
; |
16 |
|
|
|
17 |
|
|
sub new { |
18 |
|
|
#print "new: ", __PACKAGE__, "\n"; |
19 |
|
|
my $class = shift; |
20 |
|
|
my $value = shift; |
21 |
|
|
#tie(%{$value}, "Tie::IxHash"); |
22 |
|
|
#return bless \$value => $class; |
23 |
|
|
return bless $value => $class; |
24 |
|
|
} |
25 |
|
|
|
26 |
|
|
sub stringify { |
27 |
|
|
my ($x, $y) = @_; |
28 |
|
|
|
29 |
|
|
# dereference value |
30 |
|
|
# TODO: clear this!!! |
31 |
|
|
my $value; |
32 |
|
|
if ( ref($x) eq 'Hash::Serializer' ) { |
33 |
|
|
$value = $x; |
34 |
|
|
} else { |
35 |
|
|
$value = $$x; |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
my @entries; |
39 |
|
|
foreach my $h_key (keys %{$value}) { |
40 |
|
|
my $h_val = $value->{$h_key}; |
41 |
|
|
push @entries, "$h_key: $h_val"; |
42 |
|
|
} |
43 |
|
|
return join " / ", @entries; |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
|
47 |
|
|
1; |
48 |
|
|
__END__ |