1#!/usr/bin/env perl
2
3# https://rt.cpan.org/Ticket/Display.html?id=54494
4#
5# Test that smart_encode() in RPC::XML can correctly deal with blessed refs
6# by treating them as non-blessed.
7
8## no critic(RequireInterpolationOfMetachars)
9
10use strict;
11use warnings;
12
13use Test::More;
14
15use RPC::XML ':all';
16
17plan tests => 8;
18
19my ($val, $obj, $result);
20
21$val = bless { integer => 10, string => 'foo' }, 'BlessedHash';
22$result = eval { $obj = smart_encode($val); 1; };
23isa_ok($obj, 'RPC::XML::struct', '$obj');
24SKIP: {
25    if (ref($obj) ne 'RPC::XML::struct')
26    {
27        skip 'Blessed hash did not encode', 2;
28    }
29
30    my $value = $obj->value;
31    is($value->{integer}, 10, 'Converted hash integer value');
32    is($value->{string}, 'foo', 'Converted hash string value');
33}
34
35$val = bless [ 10, 'foo' ], 'BlessedArray';
36$result = eval { $obj = smart_encode($val); 1; };
37isa_ok($obj, 'RPC::XML::array', '$obj');
38SKIP: {
39    if (ref($obj) ne 'RPC::XML::array')
40    {
41        skip 'Blessed array did not encode', 2;
42    }
43
44    my $value = $obj->value;
45    is($value->[0], 10, 'Converted array integer value');
46    is($value->[1], 'foo', 'Converted array string value');
47}
48
49$val = bless \do { my $elt = 'foo' }, 'BlessedScalar';
50$result = eval { $obj = smart_encode($val); 1; };
51isa_ok($obj, 'RPC::XML::string', '$obj');
52SKIP: {
53    if (ref($obj) ne 'RPC::XML::string')
54    {
55        skip 'Blessed scalar did not encode', 1;
56    }
57
58    my $value = $obj->value;
59    is($value, 'foo', 'Converted scalar value');
60}
61
62exit;
63