| 1 | { package Catalyst::Model::SOAP; | ||
| 2 | 6 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 6 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 0 | ▶ | use XML::Compile::WSDL11; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 5 | use XML::Compile::Util qw/pack_type/; | ||
| 6 | use List::Util qw/first/; | ||
| 7 | use base qw(Catalyst::Model); | ||
| 8 | our $VERSION = '1.5'; | ||
| 9 | |||
| 10 | |||
| 11 | __PACKAGE__->mk_accessors('transport'); | ||
| 12 | |||
| 13 | use constant NS_SOAP_ENV => "http://schemas.xmlsoap.org/soap/envelope/"; | ||
| 14 | use constant NS_WSDLSOAP => "http://schemas.xmlsoap.org/wsdl/soap/"; | ||
| 15 | use XML::Compile::SOAP11; | ||
| 16 | |||
| 17 | sub register_wsdl { | ||
| 18 | my ($self, $wsdl, $target) = @_; | ||
| 19 | |||
| 20 | my $wsdl_obj; | ||
| 21 | my $schema; | ||
| 22 | |||
| 23 | if (ref $wsdl eq 'HASH') { | ||
| 24 | $schema = $wsdl->{schema}; | ||
| 25 | $wsdl = $wsdl->{wsdl} | ||
| 26 | } | ||
| 27 | |||
| 28 | if (ref $wsdl eq 'ARRAY') { | ||
| 29 | my @wsdl = @{$wsdl}; | ||
| 30 | my $main = shift @wsdl; | ||
| 31 | $wsdl_obj = XML::Compile::WSDL11->new($main); | ||
| 32 | $wsdl_obj->addWSDL($_) for @wsdl; | ||
| 33 | } else { | ||
| 34 | $wsdl_obj = XML::Compile::WSDL11->new($wsdl); | ||
| 35 | } | ||
| 36 | |||
| 37 | if (ref $schema eq 'ARRAY') { | ||
| 38 | $wsdl_obj->importDefinitions($_) for @{$schema}; | ||
| 39 | } elsif ($schema) { | ||
| 40 | $wsdl_obj->importDefinitions($schema) | ||
| 41 | } | ||
| 42 | |||
| 43 | my $transport = $self->config->{transport}; | ||
| 44 | my $service = $self->config->{service}; | ||
| 45 | |||
| 46 | if (ref $target eq 'HASH') { | ||
| 47 | # I'll have to implement a piece of XML::Compile::SOAP::WSDL11 here, | ||
| 48 | # as it doesn't provide a way to list the operations for a single port | ||
| 49 | foreach my $portname (keys %{$target}) { | ||
| 50 | my $realtarget = $self.'::'.$target->{$portname}; | ||
| 51 | no strict 'refs'; | ||
| 52 | @{$realtarget.'::ISA'} = qw(Catalyst::Model::SOAP::Instance); | ||
| 53 | |||
| 54 | for my $operation ($wsdl_obj->operations(port => $portname)) { | ||
| 55 | $self->_register_operation($wsdl_obj, $operation, $realtarget, $transport); | ||
| 56 | } | ||
| 57 | |||
| 58 | } | ||
| 59 | } else { | ||
| 60 | my $realtarget = $self.'::'.$target; | ||
| 61 | no strict 'refs'; | ||
| 62 | @{$realtarget.'::ISA'} = qw(Catalyst::Model::SOAP::Instance); | ||
| 63 | foreach my $operation ($wsdl_obj->operations()) { | ||
| 64 | $self->_register_operation($wsdl_obj, $operation, $realtarget, $transport); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | } | ||
| 68 | sub _register_operation { | ||
| 69 | my ($self, $wsdl_obj, $operation, $realtarget, $transport) = @_; | ||
| 70 | no strict 'refs'; | ||
| 71 | my $send; | ||
| 72 | if ($transport) { | ||
| 73 | $send = $transport->compileClient(kind => $operation->kind); | ||
| 74 | } | ||
| 75 | |||
| 76 | my $code = $operation->compileClient($send ? ( transport => $send ) : ()); | ||
| 77 | |||
| 78 | my $name = $operation->name(); | ||
| 79 | my $style = $operation->style; | ||
| 80 | |||
| 81 | *{$realtarget.'::'.$operation->name()} = sub { | ||
| 82 | my $self = shift; | ||
| 83 | if ($style =~ /rpc/i) { | ||
| 84 | my $ret = $code->(@_); | ||
| 85 | if (exists $ret->{$name}) { | ||
| 86 | return $ret->{$name}; | ||
| 87 | } elsif (exists $ret->{$name.'Response'}) { | ||
| 88 | return $ret->{$name.'Response'}; | ||
| 89 | } else { | ||
| 90 | return $ret; | ||
| 91 | } | ||
| 92 | } else { | ||
| 93 | return $code->(@_); | ||
| 94 | } | ||
| 95 | }; | ||
| 96 | *{$realtarget.'::_'.$operation->name().'_data'} = sub { | ||
| 97 | return ($wsdl_obj, $operation, $code); | ||
| 98 | }; | ||
| 99 | } | ||
| 100 | }; | ||
| 101 | { package Catalyst::Model::SOAP::Instance; | ||
| 102 | use strict; | ||
| 103 | use warnings; | ||
| 104 | use base qw(Catalyst::Model); | ||
| 105 | }; | ||
| 106 | |||
| 107 | |||
| 108 | 1; | ||
| 109 | |||
| 110 | __END__ | ||