Debian Codegraph @

lemonldap-ng-common/lib/Lemonldap/NG/Common/PSGI/SOAPService.pm

raw
1 ## @file
2 # SOAP wrapper used to restrict exported functions
3
4 ## @class
5 # SOAP wrapper used to restrict exported functions
6 package Lemonldap::NG::Common::PSGI::SOAPService;
7
8 use strict;
9
10 require SOAP::Lite;
11
12 our $VERSION = '2.0.10';
13
14 ## @cmethod Lemonldap::NG::Common::PSGI::SOAPService new(object obj,string @func)
15 # Constructor
16 # @param $obj object which will be called for SOAP authorized methods
17 # @param @func authorized methods
18 # @return Lemonldap::NG::Common::PSGI::SOAPService object
19 sub new {
20 my ( $class, $obj, $req, @func ) = @_;
21 s/.*::// foreach (@func);
22 return bless { obj => $obj, func => \@func, req => $req }, $class;
23 }
24
25 ## @method data AUTOLOAD()
26 # Call the wanted function with the object given to the constructor.
27 # AUTOLOAD() is a magic method called by Perl interpreter fon non existent
28 # functions. Here, we use it to call the wanted function (given by $AUTOLOAD)
29 # if it is authorized
30 # @return data provided by the exported function
31 sub AUTOLOAD {
32 my $self = shift;
33 our $AUTOLOAD =~ s/.*:://;
34 if ( grep { $_ eq $AUTOLOAD } @{ $self->{func} } ) {
35 my $tmp = $self->{obj}->$AUTOLOAD( $self->{req}, @_ );
36 unless ( ref($tmp) and ref($tmp) =~ /^SOAP/ ) {
37 $tmp = SOAP::Data->name( result => $tmp );
38 }
39 return $tmp;
40 }
41 elsif ( $AUTOLOAD ne 'DESTROY' ) {
42 die "$AUTOLOAD is not an authorized function";
43 }
44 1;
45 }
46
47 1;