1#!perl -T 2 3use strict; 4use warnings; 5use lib 't'; 6 7use Test::More tests => 36; 8 9use MyClass; 10 11do { 12 my $c = MyClass->new(); 13 is $c->call('hello'), undef; 14 is $c->run_hook('hello'), undef; 15 16 $c->load_plugins({ module => 'Hello'}); # hashref. 17 is $c->call('hello'), 'hello'; 18 is $c->run_hook('hello')->[0], 'hook hello'; 19 is scalar(@{ $c->run_hook('hello') }), 1; 20 21 $c->load_plugins({ module => 'Hello'}); # hashref. 22 is $c->call('hello'), 'hello'; 23 is $c->run_hook('hello')->[0], 'hook hello'; 24 is $c->run_hook('hello')->[1], 'hook hello'; 25 is scalar(@{ $c->run_hook('hello') }), 2; 26}; 27 28do { 29 my $c = MyClass->new(); 30 is $c->call('hello'), undef; 31 is $c->run_hook('hello'), undef; 32 33 $c->load_plugins({ module => 'Hello', config => {} }); # hashref. 34 is $c->call('hello'), 'hello'; 35 is $c->run_hook('hello')->[0], 'hook hello'; 36 is scalar(@{ $c->run_hook('hello') }), 1; 37 38 $c->load_plugins({ module => 'Hello', config => {} }); # hashref. 39 is $c->call('hello'), 'hello'; 40 is $c->run_hook('hello')->[0], 'hook hello'; 41 is $c->run_hook('hello')->[1], 'hook hello'; 42 is scalar(@{ $c->run_hook('hello') }), 2; 43}; 44 45do { 46 my $c = MyClass->new(); 47 is $c->call('hello'), undef; 48 is $c->run_hook('hello'), undef; 49 50 $c->load_plugins('Hello'); # simple string 51 is $c->call('hello'), 'hello'; 52 is $c->run_hook('hello')->[0], 'hook hello'; 53 is scalar(@{ $c->run_hook('hello') }), 1; 54 55 $c->load_plugins('Hello'); # simple string 56 is $c->call('hello'), 'hello'; 57 is $c->run_hook('hello')->[0], 'hook hello'; 58 is $c->run_hook('hello')->[1], undef; 59 is scalar(@{ $c->run_hook('hello') }), 1; 60}; 61 62do { 63 my $c = MyClass->new(); 64 is $c->call('hello'), undef; 65 is $c->run_hook('hello'), undef; 66 67 $c->load_plugins('+MyClass::Plugin::Hello'); # full path 68 is $c->call('hello'), 'hello'; 69 is $c->run_hook('hello')->[0], 'hook hello'; 70 is scalar(@{ $c->run_hook('hello') }), 1; 71 72 $c->load_plugins('+MyClass::Plugin::Hello'); # full path 73 is $c->call('hello'), 'hello'; 74 is $c->run_hook('hello')->[0], 'hook hello'; 75 is $c->run_hook('hello')->[1], undef; 76 is scalar(@{ $c->run_hook('hello') }), 1; 77}; 78