File: Ref.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (34 lines) | stat: -rw-r--r-- 1,061 bytes parent folder | download | duplicates (9)
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
use Test2::Bundle::Extended;

use Test2::Util::Ref qw/rtype render_ref/;

imported_ok qw{ render_ref rtype };

{
    package Test::A;
    package Test::B;
    use overload '""' => sub { 'A Bee!' };
}
my $ref = {a => 1};
is(render_ref($ref), "$ref", "Matches normal stringification (not blessed)");
like(render_ref($ref), qr/HASH\(0x[0-9A-F]+\)/i, "got address");

bless($ref, 'Test::A');
is(render_ref($ref), "$ref", "Matches normal stringification (blessed)");
like(render_ref($ref), qr/Test::A=HASH\(0x[0-9A-F]+\)/i, "got address and package (no overload)");

bless($ref, 'Test::B');
like(render_ref($ref), qr/Test::B=HASH\(0x[0-9A-F]+\)/i, "got address and package (with overload)");

my $x = '';
$ref = \$x;
is(rtype(undef),     '',       "not a ref");
is(rtype(''),        '',       "not a ref");
is(rtype({}),        'HASH',   "HASH");
is(rtype([]),        'ARRAY',  "ARRAY");
is(rtype($ref),      'SCALAR', "SCALAR");
is(rtype(\$ref),     'REF',    "REF");
is(rtype(sub { 1 }), 'CODE',   "CODE");
is(rtype(qr/xxx/),   'REGEXP', "REGEXP");

done_testing;