File: e11_as_nonblessed.t

package info (click to toggle)
libjson-perl 2.07-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 408 kB
  • ctags: 134
  • sloc: perl: 1,815; makefile: 44
file content (45 lines) | stat: -rw-r--r-- 656 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
45

use strict;
use Test::More;
BEGIN { plan tests => 3 };

BEGIN { $ENV{PERL_JSON_BACKEND} = 0; }

use JSON -convert_blessed_universally;


my $obj  = Test->new( [ 1, 2, {foo => 'bar'} ] );

$obj->[3] = Test2->new( { a => 'b' } );

my $json = JSON->new->allow_blessed->convert_blessed;

is( $json->encode( $obj ), '[1,2,{"foo":"bar"},"hoge"]'  );

$json->convert_blessed(0);

is( $json->encode( $obj ), 'null' );

$json->allow_blessed(0)->convert_blessed(1);

is( $json->encode( $obj ), '[1,2,{"foo":"bar"},"hoge"]'  );


package Test;

sub new {
    bless $_[1], $_[0];
}



package Test2;

sub new {
    bless $_[1], $_[0];
}

sub TO_JSON {
    "hoge";
}