| 1 |
use Test2::V0 -no_srand => 1; |
| 2 |
|
| 3 |
{ package Foo; |
| 4 |
|
| 5 |
use FFI::Build::PluginData 'plugin_data'; |
| 6 |
|
| 7 |
sub new { bless {}, __PACKAGE__ } |
| 8 |
} |
| 9 |
|
| 10 |
{ package FFI::Build::Plugin::Bar; |
| 11 |
|
| 12 |
sub new { bless {}, __PACKAGE__ } |
| 13 |
|
| 14 |
sub call_plugin_data |
| 15 |
{ |
| 16 |
my($self, $foo) = @_; |
| 17 |
$foo->plugin_data; |
| 18 |
} |
| 19 |
|
| 20 |
} |
| 21 |
|
| 22 |
my $foo = Foo->new; |
| 23 |
|
| 24 |
is( |
| 25 |
dies { $foo->plugin_data }, |
| 26 |
match qr/^plugin_data must be called by a plugin/, |
| 27 |
); |
| 28 |
|
| 29 |
is( |
| 30 |
FFI::Build::Plugin::Bar->new, |
| 31 |
object { |
| 32 |
call [call_plugin_data => $foo] => {}; |
| 33 |
call sub { |
| 34 |
my $plugin = shift; |
| 35 |
$plugin->call_plugin_data($foo)->{baz} = 1; |
| 36 |
1; |
| 37 |
} => 1; |
| 38 |
call [call_plugin_data => $foo] => { baz => 1 }; |
| 39 |
}, |
| 40 |
); |
| 41 |
|
| 42 |
is( |
| 43 |
$foo, |
| 44 |
{ plugin_data => { Bar => { baz => 1 } } }, |
| 45 |
); |
| 46 |
|
| 47 |
done_testing; |
| 48 |
|
| 49 |
1; |