-
Notifications
You must be signed in to change notification settings - Fork 14
/
90_rt54494_blessed_refs.t
50 lines (39 loc) · 1.34 KB
/
90_rt54494_blessed_refs.t
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
45
46
47
48
49
50
#!/usr/bin/perl
# https://rt.cpan.org/Ticket/Display.html?id=54494
#
# Test that smart_encode() in RPC::XML can correctly deal with blessed refs
# by treating them as non-blessed.
use strict;
use vars qw($val $obj);
use Test::More tests => 8;
use RPC::XML ':all';
$val = bless { integer => 10, string => 'foo' }, 'BlessedHash';
eval { $obj = smart_encode($val); };
isa_ok($obj, 'RPC::XML::struct', '$obj');
SKIP: {
skip 'Blessed hash did not encode', 2
unless (ref($obj) eq 'RPC::XML::struct');
my $value = $obj->value;
is($value->{integer}, 10, 'Converted hash integer value');
is($value->{string}, 'foo', 'Converted hash string value');
}
$val = bless [ 10, 'foo' ], 'BlessedArray';
eval { $obj = smart_encode($val); };
isa_ok($obj, 'RPC::XML::array', '$obj');
SKIP: {
skip 'Blessed array did not encode', 2
unless (ref($obj) eq 'RPC::XML::array');
my $value = $obj->value;
is($value->[0], 10, 'Converted array integer value');
is($value->[1], 'foo', 'Converted array string value');
}
$val = bless \do { my $elt = 'foo' }, 'BlessedScalar';
eval { $obj = smart_encode($val); };
isa_ok($obj, 'RPC::XML::string', '$obj');
SKIP: {
skip 'Blessed scalar did not encode', 1
unless (ref($obj) eq 'RPC::XML::string');
my $value = $obj->value;
is($value, 'foo', 'Converted scalar value');
}
exit;