File: globs.t

package info (click to toggle)
libdata-visitor-perl 0.30-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 204 kB
  • ctags: 49
  • sloc: perl: 1,169; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,145 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

use Data::Visitor;

our ( $FOO, %FOO );

my $glob = \*FOO;

$FOO = 3;
%FOO = ( foo => "bar" );
is( ${ *$glob{SCALAR} }, 3, "scalar glob created correctly" );
is_deeply( *$glob{HASH}, { foo => "bar" }, "hash glob created correctly" );

my $structure = [ $glob ];

my $mock;
my %called;

{
    my $meta = Class::MOP::class_of('Data::Visitor');

    my $class;
    $class = $meta->create_anon_class(
        superclasses => [$meta->name],
        methods => {
            meta => sub { $class },
            map {
                my $e = $_;
                ($e => sub { $called{$e}++; shift->${\"Data::Visitor::$e"}(@_) })
            } map { "visit_$_" } qw(hash glob value array)
        },
    );

    $mock = $class->name->new;
}

%called = ();
my $mapped = $mock->visit( $structure );

# structure sanity
is( ref $mapped, "ARRAY", "container" );
is( ref ( $mapped->[0] ), "GLOB", "glob ref" );
is( ${ *{$mapped->[0]}{SCALAR} }, 3, "value in glob's scalar slot");

ok($called{visit_array});
ok($called{visit_glob});
ok($called{visit_value});
ok($called{visit_hash});

done_testing;