File: 01func.t

package info (click to toggle)
libxs-parse-sublike-perl 0.37-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 516 kB
  • sloc: ansic: 944; perl: 930; sh: 6; makefile: 3
file content (58 lines) | stat: -rw-r--r-- 1,181 bytes parent folder | download
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
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

use lib "t";
use testcase "t::func";

BEGIN { $^H{"t::func/func"}++ }

# named func
{
   func example { return 123; }

   is( example(), 123, 'named func' );
}

# anon func
{
   my $ex2 = func { return 456; };

   is( $ex2->(), 456, 'anon func' );
}

# func still obtains :ATTRS
{
   my $modify_invoked;

   sub MODIFY_CODE_ATTRIBUTES
   {
      my ( $pkg, $sub, $attr ) = @_;
      $modify_invoked++;
      ::is( $attr, "MyCustomAttribute(value here)",
         'MODIFY_CODE_ATTRIBUTES takes attribute' );

      return ();
   }

   func withattr :MyCustomAttribute(value here) { }
   func attrnospace:MyCustomAttribute(value here) { }

   is( $modify_invoked, 2, 'MODIFY_CODE_ATTRIBUTES invoked' );
}

# named func in another package
{
   func Some::Other::Package::example { return 456; }

   is( Some::Other::Package->example, 456, 'named func in another package' );

   my $e = defined eval 'nopkgfunc Some::Other::Package::example2 { }; 1' ? undef : $@;
   like( $e, qr/^Declaring this sub-like function in another package is not permitted /,
      'nopkgfunc does not permit other package name' );
}

done_testing;