| 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::Foo; | ||
| 15 | |||
| 16 | 9 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | 9 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 9 | ▶ | no warnings 'uninitialized'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | |||
| 20 | 9 | ▶ | use RPC::ExtDirect; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | |||
| 22 | # Return scalar result | ||
| 23 | 7 | ▶ | sub foo_foo : ExtDirect(1, before => \&foo_before) { |
|
Subroutine
foo_foo: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 24 | 7 | return "foo! '${_[1]}'" | |
| 25 | 9 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 26 | |||
| 27 | # Return arrayref result | ||
| 28 | sub foo_bar | ||
| 29 | 3 | ▶ | : ExtDirect(2, instead => \&foo_instead) |
|
Subroutine
foo_bar: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 30 | { | ||
| 31 | 3 | return [ 'foo! bar!', @_[1, 2], ]; | |
| 32 | 9 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 33 | |||
| 34 | # Return hashref result | ||
| 35 | 5 | ▶ | sub foo_baz : ExtDirect( params => [foo, bar, baz], before => \&foo_before, after => \&foo_after) { |
|
Subroutine
foo_baz: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 36 | 5 | my $class = shift; | |
| 37 | 5 | my %param = @_; | |
| 38 | |||
| 39 | my $ret = { msg => 'foo! bar! baz!', foo => $param{foo}, | ||
| 40 | bar => $param{bar}, baz => $param{baz}, | ||
| 41 | 5 | }; | |
| 42 | |||
| 43 | 5 | delete @param{ qw(foo bar baz) }; | |
| 44 | 5 | @$ret{ keys %param } = values %param; | |
| 45 | |||
| 46 | 5 | return $ret; | |
| 47 | 9 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 48 | |||
| 49 | # Testing zero parameters | ||
| 50 | 0 | ▶ | sub foo_zero : ExtDirect(0) { |
|
Subroutine
foo_zero: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 51 | 0 | my ($class) = @_; | |
| 52 | |||
| 53 | 0 | my $ret = [ @_ ]; | |
| 54 | |||
| 55 | 0 | return $ret; | |
| 56 | 9 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 57 | |||
| 58 | # Testing blessed object return | ||
| 59 | 1 | ▶ | sub foo_blessed : ExtDirect { |
|
Subroutine
foo_blessed: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 60 | 1 | return bless {}, 'foo'; | |
| 61 | 9 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 62 | |||
| 63 | # Testing hooks | ||
| 64 | 3 | ▶ | sub foo_before { |
|
Subroutine
foo_before: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 65 | 3 | return 1; | |
| 66 | } | ||
| 67 | |||
| 68 | 1 | ▶ | sub foo_instead { |
|
Subroutine
foo_instead: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 69 | 1 | my ($class, %params) = @_; | |
| 70 | |||
| 71 | 1 | return $params{orig}->(); | |
| 72 | } | ||
| 73 | |||
| 74 | 2 | ▶ | sub foo_after { |
|
Subroutine
foo_after: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 75 | } | ||
| 76 | |||
| 77 | 9 | 1; | |