[Catalyst-commits] r7180 - in Catalyst-Model-SOAP/1.0/trunk: lib/Catalyst/Model t t/lib

ruoso at dev.catalyst.perl.org ruoso at dev.catalyst.perl.org
Wed Nov 28 15:33:30 GMT 2007


Author: ruoso
Date: 2007-11-28 15:33:30 +0000 (Wed, 28 Nov 2007)
New Revision: 7180

Modified:
   Catalyst-Model-SOAP/1.0/trunk/lib/Catalyst/Model/SOAP.pm
   Catalyst-Model-SOAP/1.0/trunk/t/01_basics.t
   Catalyst-Model-SOAP/1.0/trunk/t/lib/MyXMLModule.pm
Log:
[C-M-SOAP] first tests work, the closures are already created...

Modified: Catalyst-Model-SOAP/1.0/trunk/lib/Catalyst/Model/SOAP.pm
===================================================================
--- Catalyst-Model-SOAP/1.0/trunk/lib/Catalyst/Model/SOAP.pm	2007-11-27 11:19:43 UTC (rev 7179)
+++ Catalyst-Model-SOAP/1.0/trunk/lib/Catalyst/Model/SOAP.pm	2007-11-28 15:33:30 UTC (rev 7180)
@@ -2,10 +2,31 @@
     use strict;
     use warnings;
     use XML::Compile::SOAP;
+    use base qw(Catalyst::Model Class::Data::Accessor);
     our $VERSION = '0.0.1';
 
+    __PACKAGE__->mk_classaccessor('wsdl_classes' => {});
+
     sub register_wsdl {
+        my ($self, $wsdl, $target) = @_;
 
+        no strict 'refs';
+        my $wsdl_obj = XML::Compile::SOAP::WSDL11->new($wsdl);
+        my $realtarget = $self.'::'.$target;
+
+        foreach my $operation ($wsdl_obj->operations(produce => 'OBJECTS')) {
+            my $code = $operation->compileClient();
+            *{$realtarget.'::'.$operation->name()} = sub {
+                my $self = shift;
+                return $code->(@_);
+            };
+            *{$realtarget.'::_'.$operation->name().'_data'} = sub {
+                return ($wsdl_obj, $operation, $code);
+            };
+        }
+
+        $self->wsdl_classes->{$realtarget} = 1;
+
     }
 };
 1;
@@ -21,14 +42,14 @@
   {# In the model class...
       package MyApp::Model::SOAP;
       use base qw(Catalyst::Model::SOAP);
-      __PACKAGE__->register_wsdl('http://foo.bar/baz.wsdl', 'Bar::Baz');
-      __PACKAGE__->register_wsdl('http://baz.bar/foo.wsdl', 'Bar::Foo');
+      __PACKAGE__->register_wsdl('http://foo.bar/baz.wsdl', 'SOAP::Baz');
+      __PACKAGE__->register_wsdl('http://baz.bar/foo.wsdl', 'SOAP::Foo');
   };
   {# later in some other class..
-     $c->model('Bar::Baz')->getWeather(%arguments);
+     $c->model('SOAP::Baz')->getWeather(%arguments);
      # is then dispatched to the operation getWeather described by the
      # first wsdl...
-     $c->model('Bar::Foo')->foo(%arguments);
+     $c->model('SOAP::Foo')->foo(%arguments);
      # is then dispatched to the operation foo described by the
      # second wsdl...
   };
@@ -44,6 +65,22 @@
 by XML::Compile::SOAP::WSDL, as a Model class, where each operation in
 the wsdl file is represented by a method with the same name.
 
+=head1 METHODS
+
+=over
+
+=item register_wsdl($wsdl, $targetclass)
+
+This method will register the operations described by $wsdl in the
+$targetclass package. $wsdl may be anythin XML::Compile::SOAP::WSDL11
+accepts, the $targetclass is a relative package name which will be
+concatenated in the name of the model.
+
+Note that XML::Compile->knownNamespace(...) can be used to help
+declaring the wsdl.
+
+=back
+
 =head1 ACCESSORS
 
 For each operation, a secondary method called _$operation_data is

Modified: Catalyst-Model-SOAP/1.0/trunk/t/01_basics.t
===================================================================
--- Catalyst-Model-SOAP/1.0/trunk/t/01_basics.t	2007-11-27 11:19:43 UTC (rev 7179)
+++ Catalyst-Model-SOAP/1.0/trunk/t/01_basics.t	2007-11-28 15:33:30 UTC (rev 7180)
@@ -12,11 +12,10 @@
     __PACKAGE__->register_wsdl('http://foo.bar/baz.wsdl', 'Bar::Baz');
 };
 
-ok(defined *::Bar::Baz, 'Loading the wsdl pre-registers a class.');
-ok(defined *::Bar::Baz::op1, 'Loading the wsdl pre-registers the method.');
-ok(defined *::Bar::Baz::_op1_data, 'Loading the wsdl pre-register the helper-method');
-is(::Bar::Baz->op1, 'op1', 'The method calls the coderef.');
-my @data = ::Bar::Baz->_op1_data();
+ok(defined *{::MyFooModel::Bar::Baz::op1}, 'Loading the wsdl pre-registers the method.');
+ok(defined *{::MyFooModel::Bar::Baz::_op1_data}, 'Loading the wsdl pre-register the helper-method');
+is(MyFooModel::Bar::Baz->op1, 'op1', 'The method calls the coderef.');
+my @data = MyFooModel::Bar::Baz->_op1_data();
 is(ref $data[0], 'MyXML::WSDL11', 'The first element in the data is the wsdl object');
 is(ref $data[1], 'MyXML::Operation', 'The second element in the data is the operation object');
 is(ref $data[2], 'CODE', 'The third element in the data is the code reference');

Modified: Catalyst-Model-SOAP/1.0/trunk/t/lib/MyXMLModule.pm
===================================================================
--- Catalyst-Model-SOAP/1.0/trunk/t/lib/MyXMLModule.pm	2007-11-27 11:19:43 UTC (rev 7179)
+++ Catalyst-Model-SOAP/1.0/trunk/t/lib/MyXMLModule.pm	2007-11-28 15:33:30 UTC (rev 7180)
@@ -4,6 +4,7 @@
 # XML::Compile::SOAP and depending on network.
 {
     package XML::Compile::SOAP::WSDL11;
+    use Symbol;
     sub new {
         return bless { symbol => gensym() }, MyXML::WSDL11;
     }
@@ -12,13 +13,13 @@
     package MyXML::WSDL11;
     sub operations {
         return
-          [
+          (
            (bless { name => 'op1', service => 'sv1', port => 'pt1' }, MyXML::Operation),
            (bless { name => 'op2', service => 'sv1', port => 'pt1' }, MyXML::Operation),
            (bless { name => 'op3', service => 'sv1', port => 'pt2' }, MyXML::Operation),
            (bless { name => 'op4', service => 'sv2', port => 'pt3' }, MyXML::Operation),
            (bless { name => 'op5', service => 'sv2', port => 'pt4' }, MyXML::Operation),
-          ]
+          )
     }
 };
 {




More information about the Catalyst-commits mailing list