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   1124 use strict;
  2         4  
  2         65  
17 2     2   9 use warnings;
  2         2  
  2         58  
18 2     2   13 no warnings 'uninitialized';
  2         2  
  2         81  
19              
20 2     2   389 use RPC::ExtDirect before => \&nonexistent_before_hook;
  2         5  
  2         23  
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   12 }
  2         3  
  2         11  
27              
28             sub foo_bar : ExtDirect(2, before => 'NONE') {
29 1     1 0 4 $foo_bar_called = 1;
30 2     2   307 }
  2         4  
  2         8  
31              
32             # This hook will simply raise a flag and die
33             sub foo_baz_after {
34 1     1 0 2 $foo_baz_called = 1;
35              
36 1         14 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 2 my $class = shift;
43 1         3 my %param = @_;
44              
45             my $ret = { msg => 'foo! bar! baz!', foo => $param{foo},
46             bar => $param{bar}, baz => $param{baz},
47 1         5 };
48              
49 1         3 delete @param{ qw(foo bar baz) };
50 1         3 @$ret{ keys %param } = values %param;
51              
52 1         3 return $ret;
53 2     2   480 }
  2         2  
  2         8  
54              
55             # Testing hook changing parameters
56             sub foo_hook : ExtDirect(1) {
57 3     3 0 4 my ($class, $foo) = @_;
58              
59 3         4 my $ret = [ @_ ];
60              
61 3         8 return $ret;
62 2     2   290 }
  2         4  
  2         8  
63              
64             1;
65