| 1 | package XML::Compile::SOAP::Daemon::Dancer2; | ||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 3 | ▶ | use 5.008_005; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 3 | our $VERSION = '0.07'; | |||||||||||
| 6 | 3 | ▶ | use Dancer2::Plugin; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 3 | ▶ | use Dancer2::FileUtils 'path'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 3 | ▶ | use Class::Load qw(try_load_class); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 3 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 3 | ▶ | use XML::Compile::SOAP::Daemon::Dancer2::Handler; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 3 | ▶ | use XML::Compile::WSDL11; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 3 | ▶ | use XML::Compile::SOAP11; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 3 | ▶ | use XML::Compile::SOAP12; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | |||||||||||||
| 16 | 2 | ▶ | sub get_implementation { | ||||||||||
|
Subroutine
get_implementation: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||
| 17 | 2 | my ( $class_name, $dsl ) = @_; | |||||||||||
| 18 | 2 | my ($ok, $error) = try_load_class($class_name); | |||||||||||
| 19 | 2 | ▶ | if (! $ok) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 20 | 0 | confess "Cannot load implementation class $class_name: $error"; | |||||||||||
| 21 | } | ||||||||||||
| 22 | |||||||||||||
| 23 | 2 | my $implementation = $class_name->new( dsl => $dsl ); | |||||||||||
| 24 | |||||||||||||
| 25 | 2 | ▶ | die "Implementation class needs to do the role XML::Compile::SOAP::Daemon::Dancer2::Role::Implementation" | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | unless $implementation->DOES('XML::Compile::SOAP::Daemon::Dancer2::Role::Implementation'); | ||||||||||||
| 27 | |||||||||||||
| 28 | 2 | return $implementation; | |||||||||||
| 29 | } | ||||||||||||
| 30 | |||||||||||||
| 31 | 4 | ▶ | register 'wsdl_endpoint' => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=14 SCAR=27.9
| |||||||||||||
| 32 | 4 | my ($dsl, $path, $options) = @_; | |||||||||||
| 33 | |||||||||||||
| 34 | 4 | my $settings = plugin_setting; | |||||||||||
| 35 | 4 | ▶ | my $wsdl_path = path( $dsl->setting('appdir'), $settings->{wsdl_path}//"wsdl" ); | ||||||||||
|
Condition50%1/2
$settings->{"wsdl_path"} // "wsdl"
MC/DC0%0/1
$settings->{"wsdl_path"} // "wsdl"
$settings->{"wsdl_path"}
Truth table50%1/2
A
A= $settings->{"wsdl_path"}
| |||||||||||||
| 36 | 4 | ▶ | my $xsd_path = path( $dsl->setting('appdir'), $settings->{xsd_path}//"wsdl" ); | ||||||||||
|
Condition50%1/2
$settings->{"xsd_path"} // "wsdl"
MC/DC0%0/1
$settings->{"xsd_path"} // "wsdl"
$settings->{"xsd_path"}
Truth table50%1/2
A
A= $settings->{"xsd_path"}
| |||||||||||||
| 37 | |||||||||||||
| 38 | 4 | for my $key ( qw(wsdl) ) { | |||||||||||
| 39 | 4 | ▶ | confess "$key option mandatory when calling wsdl_endpoint" unless exists $options->{$key}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 40 | } | ||||||||||||
| 41 | |||||||||||||
| 42 | 4 | my $wsdl_file = path( $wsdl_path, $options->{wsdl} ); | |||||||||||
| 43 | 4 | ▶ | unless( -f $wsdl_file ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | 0 | confess "wsdl file not found ($wsdl_file)"; | |||||||||||
| 45 | } | ||||||||||||
| 46 | |||||||||||||
| 47 | 4 | my $wsdl = XML::Compile::WSDL11->new( $wsdl_file ); | |||||||||||
| 48 | |||||||||||||
| 49 | 4 | ▶ | if( exists $options->{xsd} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 50 | 4 | ▶ | if( ref $options->{xsd} eq 'ARRAY' ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | 4 | for my $file ( @{$options->{xsd}} ) { | |||||||||||
| 52 | 0 | my $xsd_file = path( $xsd_path, $file ); | |||||||||||
| 53 | 0 | $wsdl->importDefinitions( $xsd_file ); | |||||||||||
| 54 | } | ||||||||||||
| 55 | } else { | ||||||||||||
| 56 | 0 | confess 'xsd must be an array ref of xsd files'; | |||||||||||
| 57 | } | ||||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | 4 | my $operations = {}; | |||||||||||
| 61 | 4 | ▶ | if( exists $options->{operations} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | 2 | ▶ | confess "operation should be a hasref of operation => sub {}" unless ref $options->{operations} eq "HASH"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 63 | 2 | $operations = $options->{operations}; | |||||||||||
| 64 | } | ||||||||||||
| 65 | 4 | ▶ | if( exists $options->{implementation_class} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | #class provided for inplementation | ||||||||||||
| 67 | #try to load the class | ||||||||||||
| 68 | 2 | my $implementation = get_implementation( $options->{implementation_class}, $dsl ); | |||||||||||
| 69 | |||||||||||||
| 70 | 2 | for my $operation ( $wsdl->operations() ) { | |||||||||||
| 71 | #$dsl->error( $operation->action ); | ||||||||||||
| 72 | 2 | ▶ | if( my $call = $implementation->can("soapaction_".$operation->action) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 73 | 2 | ▶ | $operations->{$operation->action} = sub { $implementation->$call( @_ ) }; | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 74 | } | ||||||||||||
| 75 | } | ||||||||||||
| 76 | } | ||||||||||||
| 77 | |||||||||||||
| 78 | 4 | my $daemon = XML::Compile::SOAP::Daemon::Dancer2::Handler->new(); | |||||||||||
| 79 | |||||||||||||
| 80 | 4 | $daemon->operationsFromWSDL( | |||||||||||
| 81 | $wsdl, | ||||||||||||
| 82 | callbacks => $operations, | ||||||||||||
| 83 | ); | ||||||||||||
| 84 | |||||||||||||
| 85 | $dsl->app->add_route( | ||||||||||||
| 86 | method => 'get', | ||||||||||||
| 87 | regexp => $path, | ||||||||||||
| 88 | 4 | ▶ | code => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||
| 89 | 4 | my $params = $dsl->params; | |||||||||||
| 90 | |||||||||||||
| 91 | 4 | ▶ | if( exists $params->{wsdl} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 92 | 4 | $dsl->content_type( 'application/wsdl+xml' ); | |||||||||||
| 93 | 4 | $dsl->send_file( $wsdl_file , system_path => 1 ); | |||||||||||
| 94 | } | ||||||||||||
| 95 | } | ||||||||||||
| 96 | 4 | ); | |||||||||||
| 97 | |||||||||||||
| 98 | $dsl->app->add_route( | ||||||||||||
| 99 | method => 'post', | ||||||||||||
| 100 | regexp => $path, | ||||||||||||
| 101 | 4 | ▶ | code => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 102 | 4 | $daemon->handle( $dsl ); | |||||||||||
| 103 | } | ||||||||||||
| 104 | 4 | ); | |||||||||||
| 105 | 3 | }; | |||||||||||
| 106 | |||||||||||||
| 107 | 3 | register_plugin; | |||||||||||
| 108 | 3 | 1; | |||||||||||
| 109 | __END__ | ||||||||||||