File: ffi_build_plugindata.t

package info (click to toggle)
libffi-platypus-perl 2.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,860 kB
  • sloc: perl: 7,388; ansic: 6,862; cpp: 53; sh: 19; makefile: 14
file content (49 lines) | stat: -rw-r--r-- 744 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
use Test2::V0 -no_srand => 1;

{ package Foo;

  use FFI::Build::PluginData 'plugin_data';

  sub new { bless {}, __PACKAGE__ }
}

{ package FFI::Build::Plugin::Bar;

  sub new { bless {}, __PACKAGE__ }

  sub call_plugin_data
  {
    my($self, $foo) = @_;
    $foo->plugin_data;
  }

}

my $foo = Foo->new;

is(
  dies { $foo->plugin_data },
  match qr/^plugin_data must be called by a plugin/,
);

is(
  FFI::Build::Plugin::Bar->new,
  object {
    call [call_plugin_data => $foo] => {};
    call sub {
      my $plugin = shift;
      $plugin->call_plugin_data($foo)->{baz} = 1;
      1;
    } => 1;
    call [call_plugin_data => $foo] => { baz => 1 };
  },
);

is(
  $foo,
  { plugin_data => { Bar => { baz => 1 } } },
);

done_testing;

1;