File Coverage

blib/lib/RPC/ExtDirect/Test/Pkg/Hooks.pm
Criterion Covered Total %
statement 36 37 97.3
branch n/a
condition n/a
subroutine 12 13 92.3
pod 0 5 0.0
total 48 55 87.2


line stmt bran cond sub pod time code
1             #
2             # WARNING WARNING WARNING
3             #
4             # DO NOT CHANGE ANYTHING IN THIS MODULE. OTHERWISE, A LOT OF API
5             # AND OTHER TESTS MAY BREAK.
6             #
7             # This module is here to test certain behaviors. If you need
8             # to test something else, add another test module.
9             # It's that simple.
10             #
11              
12             # This does not need to be indexed by PAUSE
13             package
14             RPC::ExtDirect::Test::Pkg::Hooks;
15              
16 2     2   807 use strict;
  2         2  
  2         44  
17 2     2   6 use warnings;
  2         2  
  2         43  
18 2     2   10 no warnings 'uninitialized';
  2         2  
  2         66  
19              
20 2     2   295 use RPC::ExtDirect before => \&nonexistent_before_hook;
  2         5  
  2         11  
21              
22             our ($foo_foo_called, $foo_bar_called, $foo_baz_called);
23              
24             sub foo_foo : ExtDirect(1) {
25 0     0 0 0 $foo_foo_called = 1;
26 2     2   7 }
  2         2  
  2         9  
27              
28             sub foo_bar : ExtDirect(2, before => 'NONE') {
29 1     1 0 5 $foo_bar_called = 1;
30 2     2   207 }
  2         2  
  2         7  
31              
32             # This hook will simply raise a flag and die
33             sub foo_baz_after {
34 1     1 0 3 $foo_baz_called = 1;
35              
36 1         20 die;
37             }
38              
39             # Return hashref result
40             sub foo_baz : ExtDirect( params => [foo, bar, baz], before => 'NONE', after => \&foo_baz_after)
41             {
42 1     1 0 4 my $class = shift;
43 1         4 my %param = @_;
44              
45             my $ret = { msg => 'foo! bar! baz!', foo => $param{foo},
46             bar => $param{bar}, baz => $param{baz},
47 1         6 };
48              
49 1         3 delete @param{ qw(foo bar baz) };
50 1         4 @$ret{ keys %param } = values %param;
51              
52 1         7 return $ret;
53 2     2   365 }
  2         2  
  2         6  
54              
55             # Testing hook changing parameters
56             sub foo_hook : ExtDirect(1) {
57 3     3 0 4 my ($class, $foo) = @_;
58              
59 3         6 my $ret = [ @_ ];
60              
61 3         8 return $ret;
62 2     2   278 }
  2         3  
  2         7  
63              
64             1;
65