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

46 lines
1.4 KiB
Perl
Raw Normal View History

## @file
# SOAP wrapper used to restrict exported functions
## @class
# SOAP wrapper used to restrict exported functions
2017-01-07 19:04:20 +01:00
package Lemonldap::NG::Common::PSGI::SOAPService;
2009-02-08 18:12:42 +01:00
require SOAP::Lite;
2019-02-12 18:21:38 +01:00
our $VERSION = '2.1.0';
2017-01-07 19:04:20 +01:00
## @cmethod Lemonldap::NG::Common::PSGI::SOAPService new(object obj,string @func)
# Constructor
2019-09-18 20:58:51 +02:00
# @param $obj object which will be called for SOAP authorized methods
# @param @func authorized methods
2017-01-07 19:04:20 +01:00
# @return Lemonldap::NG::Common::PSGI::SOAPService object
sub new {
2017-01-07 21:37:07 +01:00
my ( $class, $obj, $req, @func ) = @_;
2010-03-01 21:32:28 +01:00
s/.*::// foreach (@func);
2017-01-07 21:37:07 +01:00
return bless { obj => $obj, func => \@func, req => $req }, $class;
}
## @method data AUTOLOAD()
# Call the wanted function with the object given to the constructor.
# AUTOLOAD() is a magic method called by Perl interpreter fon non existent
# functions. Here, we use it to call the wanted function (given by $AUTOLOAD)
2019-09-18 20:58:51 +02:00
# if it is authorized
# @return data provided by the exported function
sub AUTOLOAD {
my $self = shift;
$AUTOLOAD =~ s/.*:://;
2010-03-01 21:32:28 +01:00
if ( grep { $_ eq $AUTOLOAD } @{ $self->{func} } ) {
2017-01-07 21:37:07 +01:00
my $tmp = $self->{obj}->$AUTOLOAD( $self->{req}, @_ );
unless ( ref($tmp) and ref($tmp) =~ /^SOAP/ ) {
2009-02-08 18:12:42 +01:00
$tmp = SOAP::Data->name( result => $tmp );
}
return $tmp;
}
2010-03-01 21:32:28 +01:00
elsif ( $AUTOLOAD ne 'DESTROY' ) {
2019-07-20 16:03:38 +02:00
die "$AUTOLOAD is not an authorized function";
}
1;
}
1;