summaryrefslogtreecommitdiff
path: root/t/node-info.t
blob: ab66d3269df728d9080058b43ff268402b12bc3e (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
use strict;
use lib -e 't' ? 't' : 'test';
use TestYAML tests => 16;
use YAML::Dumper;

package StrIngy;
use overload '""', sub { 'A Stringy String' };
sub new {bless {}, shift}

package main;
my $object = bless {}, 'StrIngy';

# $\ = "\n";
# print ref($object);
# print "$object";
# print overload::StrVal($object);
# print overload::StrVal(bless {}, 'foo');
# exit;

filters {
    node => ['eval_perl' => 'get_info'],
    info => ['lines' => 'make_regexp'],
};

run_like node => 'info';

sub eval_perl {
    my $perl = shift;
    my $stringify = 0;
    $stringify = 1 if $perl =~ s/^#\s*//;
    my $node = eval $perl;
    die "Perl code failed to eval:\n$perl\n$@" if $@;
    return ($node, $stringify);
}

sub get_info {
    my $dumper = YAML::Dumper->new;
    join ';', map {
        defined($_) ? $_ : 'undef'
    } $dumper->node_info(@_);
}

sub make_regexp {
    my $string = join ';', map {
        chomp;
        s/^~$/undef/;
        s/^0x\d+/0x[0-9a-fA-F]+/;
        $_;
    } @_;
    qr/^${string}$/;
}

__DATA__
=== Hash Ref
+++ node: +{1..4};
+++ info
~
HASH
0x12345678

=== Array Ref
+++ node: [1..5]
+++ info
~
ARRAY
0x12345678

=== Scalar
+++ node: 'hello';
+++ info
~
~
0x12345678-S

=== Scalar Ref
+++ node: \ 'hello';
+++ info
~
SCALAR
0x12345678

=== Scalar Ref Ref
+++ node: \\ 'hello';
+++ info
~
REF
0x12345678

=== Code Ref
+++ node: sub { 42; }
+++ info
~
CODE
0x12345678

=== Code Ref Ref
+++ node: \ sub { 42; }
+++ info
~
REF
0x12345678

=== Glob
+++ node: $::x = 5; \ *x;
+++ info
~
GLOB
0x12345678

=== Regular Expression
+++ node: qr{xxx};
+++ info
~
REGEXP
0x12345678

=== Blessed Hash Ref
+++ node: bless {}, 'ARRAY';
+++ info
ARRAY
HASH
0x12345678

=== Blessed Array Ref
+++ node: bless [], 'Foo::Bar';
+++ info
Foo::Bar
ARRAY
0x12345678

=== Blessed Scalar Ref
+++ node: my $b = 'boomboom'; bless ((\ $b), 'Foo::Barge');
+++ info
Foo::Barge
SCALAR
0x12345678

=== Blessed Code Ref
+++ node: bless sub { 43 }, 'Foo::Barbie';
+++ info
Foo::Barbie
CODE
0x12345678

=== Blessed Glob
+++ node: $::x = 5; bless \ *x, 'Che';
+++ info
Che
GLOB
0x12345678

=== Not Stringified Hash Object
+++ node: bless {}, 'StrIngy';
+++ info
StrIngy
HASH
0x12345678

=== Stringified Hash Object
+++ node: # bless {}, 'StrIngy';
+++ info
~
~
0x12345678-S