File: eval.t

package info (click to toggle)
libkeyword-simple-perl 0.04-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 116 kB
  • sloc: perl: 128; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,003 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
46
47
48
49
50
51
52
53
54
55
56
57
58
#!perl
use strict;
use warnings FATAL => 'all';
no warnings 'once';

use Test::More;

{
    package Foo;

    use Keyword::Simple;

    sub import {
        Keyword::Simple::define class => sub {
            substr ${$_[0]}, 0, 0, "package";
        };
    }

    sub unimport {
        Keyword::Simple::undefine 'peek';
    }

    BEGIN { $INC{"Foo.pm"} = 1; }
}

use Foo;

{ class Gpkg0; our $v = __PACKAGE__; }
is $Gpkg0::v, 'Gpkg0';

eval q{ class Gpkg1; our $v = __PACKAGE__ };
is $@, '';
is $Gpkg1::v, 'Gpkg1';

SKIP: {
    skip "evalbytes() requires v5.16", 3
        if $^V lt v5.16;
    my $err;
    eval q{
        use v5.16;
        evalbytes q{ class Gpkg2; our $v = __PACKAGE__ };
        $err = $@;
    };
    is $@, '';
    is $err, '';
    is $Gpkg2::v, 'Gpkg2';
}

TODO: {
    local $TODO = 's//.../e handling is broken';
    my $str = '';
    eval q{ $str =~ s/^/ class Gpkg3; our $v = __PACKAGE__ /e };
    is $@, '';
    is $str, 'Gpkg3';
    is $Gpkg3::v, 'Gpkg3';
}

done_testing;