File Coverage

blib/lib/SOAP/WSDL/Server/Dancer2.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package SOAP::WSDL::Server::Dancer2;
2              
3             # ABSTRACT: Dancer2 for SOAP::WSDL Server
4              
5 1     1   595220 use Carp;
  1         2  
  1         123  
6 1     1   733 use Dancer2::Plugin;
  1         135992  
  1         11  
7 1     1   159 use Class::Load 'load_class';
  1         3  
  1         483  
8              
9             our $VERSION = '0.01';
10              
11             register soap_wsdl_server => sub {
12             my ($dsl, @args) = plugin_args(@_);
13             my %args = @args % 2 ? %{$args[0]} : @args;
14              
15             # Perl module with the SOAP method implementation
16             my $dispatch_to = $args{dispatch_to} or do {
17             $dsl->error('dispatch_to is required.');
18             $dsl->status(500);
19             return;
20             };
21             load_class($dispatch_to);
22              
23             # Perl module with the SOAP::WSDL server implementation
24             my $soap_service = $args{soap_service} or do {
25             $dsl->error('soap_service is required.');
26             $dsl->status(500);
27             return;
28             };
29             load_class($soap_service);
30              
31             # if no transport class was specified, use this package's
32             # Transport class with its handle() method
33             my $transport_class = $args{transport_class} || __PACKAGE__ . '::Transport';
34             load_class($transport_class);
35              
36             my $server = $soap_service->new({
37             dispatch_to => $dispatch_to, # methods
38             transport_class => $transport_class, # handle() class
39             });
40              
41             my $response_msg = $server->handle($dsl->request, $dsl->app);
42             if (defined $response_msg && $response_msg =~ /^\d{3}$/) {
43             $dsl->error("Dispatcher returned HTTP $response_msg");
44             $dsl->status($response_msg);
45             return;
46             }
47              
48             if ($response_msg) {
49             $dsl->content_type('text/xml; charset="utf-8"');
50             $dsl->response->content($response_msg);
51             return;
52             } else {
53             $dsl->error("No response returned from dispatcher");
54             $dsl->status(500);
55             return;
56             }
57             };
58              
59             register_plugin;
60              
61             1;
62             __END__