Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

RPC::XML::Procedure test-coverage improvement.

Also removed some unneeded code.
  • Loading branch information...
commit ffb4ccff320e9b521308c81279845d5a67eb64f8 1 parent b8f9437
Randy J. Ray authored
82  lib/RPC/XML/Procedure.pm
@@ -21,7 +21,6 @@
21 21
 #                   version      /
22 22
 #                   hidden      /
23 23
 #                   clone
24  
-#                   is_valid
25 24
 #                   add_signature
26 25
 #                   delete_signature
27 26
 #                   make_sig_table
@@ -52,9 +51,10 @@ use 5.008008;
52 51
 use strict;
53 52
 use warnings;
54 53
 use vars qw($VERSION);
55  
-use subs qw(new is_valid name code signature help version hidden
56  
-    add_signature delete_signature make_sig_table match_signature
57  
-    reload load_xpl_file);
  54
+use subs qw(
  55
+    new name code signature help version hidden add_signature
  56
+    delete_signature make_sig_table match_signature reload load_xpl_file
  57
+);
58 58
 
59 59
 use File::Spec;
60 60
 use Scalar::Util 'blessed';
@@ -64,7 +64,7 @@ use RPC::XML 'smart_encode';
64 64
 # This module also provides RPC::XML::Method
65 65
 ## no critic (ProhibitMultiplePackages)
66 66
 
67  
-$VERSION = '1.26';
  67
+$VERSION = '1.27';
68 68
 $VERSION = eval $VERSION;    ## no critic (ProhibitStringyEval)
69 69
 
70 70
 ###############################################################################
@@ -160,13 +160,17 @@ sub new
160 160
         }
161 161
     }
162 162
 
163  
-    if (! ((exists $data->{signature}) &&
164  
-           (ref($data->{signature}) eq 'ARRAY') &&
165  
-           scalar(@{$data->{signature}}) &&
166  
-           $data->{name} &&
167  
-           $data->{code}))
  163
+    # A sanity check on the content of the object before we bless it:
  164
+    if (! ($data->{name} && $data->{code}))
168 165
     {
169  
-        return "${class}::new: Missing required data";
  166
+        return "${class}::new: Missing required data (name or code)";
  167
+    }
  168
+    if (($class ne 'RPC::XML::Function') &&
  169
+        (! ((exists $data->{signature}) &&
  170
+            (ref($data->{signature}) eq 'ARRAY') &&
  171
+            scalar(@{$data->{signature}}))))
  172
+    {
  173
+        return "${class}::new: Missing required data (signatures)";
170 174
     }
171 175
     bless $data, $class;
172 176
 
@@ -340,29 +344,6 @@ sub clone
340 344
 
341 345
 ###############################################################################
342 346
 #
343  
-#   Sub Name:       is_valid
344  
-#
345  
-#   Description:    Boolean test to tell if the calling object has sufficient
346  
-#                   data to be used as a server method for RPC::XML::Server or
347  
-#                   Apache::RPC::Server.
348  
-#
349  
-#   Arguments:      NAME      IN/OUT  TYPE      DESCRIPTION
350  
-#                   $self     in      ref       Object to test
351  
-#
352  
-#   Returns:        Success:    1, valid/complete
353  
-#                   Failure:    0, invalid/incomplete
354  
-#
355  
-###############################################################################
356  
-sub is_valid
357  
-{
358  
-    my $self = shift;
359  
-
360  
-    return ((ref($self->{code}) eq 'CODE') && $self->{name} &&
361  
-            (ref($self->{signature}) && scalar(@{$self->{signature}})));
362  
-}
363  
-
364  
-###############################################################################
365  
-#
366 347
 #   Sub Name:       add_signature
367 348
 #                   delete_signature
368 349
 #
@@ -752,7 +733,6 @@ use vars qw(@ISA);
752 733
 #
753 734
 #   Functions:      signature
754 735
 #                   make_sig_table (called by some superclass methods)
755  
-#                   is_valid
756 736
 #                   add_signature
757 737
 #                   delete_signature
758 738
 #                   match_signature
@@ -764,7 +744,7 @@ package RPC::XML::Function;
764 744
 use strict;
765 745
 use warnings;
766 746
 use vars qw(@ISA);
767  
-use subs qw(new signature make_sig_table clone is_valid match_signature);
  747
+use subs qw(new signature make_sig_table clone match_signature);
768 748
 
769 749
 @ISA = qw(RPC::XML::Procedure);
770 750
 
@@ -777,28 +757,6 @@ sub delete_signature { return shift; }
777 757
 
778 758
 ###############################################################################
779 759
 #
780  
-#   Sub Name:       is_valid
781  
-#
782  
-#   Description:    Boolean test to tell if the calling object has sufficient
783  
-#                   data to be used as a server method for RPC::XML::Server or
784  
-#                   Apache::RPC::Server.
785  
-#
786  
-#   Arguments:      NAME      IN/OUT  TYPE      DESCRIPTION
787  
-#                   $self     in      ref       Object to test
788  
-#
789  
-#   Returns:        Success:    1, valid/complete
790  
-#                   Failure:    0, invalid/incomplete
791  
-#
792  
-###############################################################################
793  
-sub is_valid
794  
-{
795  
-    my $self = shift;
796  
-
797  
-    return ((ref $self->{code} eq 'CODE') and $self->{name});
798  
-}
799  
-
800  
-###############################################################################
801  
-#
802 760
 #   Sub Name:       match_signature
803 761
 #
804 762
 #   Description:    Noop. Needed for RPC::XML::Server.
@@ -991,14 +949,6 @@ value.
991 949
 Returns or sets the version string for the method (overwriting as with the
992 950
 other accessors).
993 951
 
994  
-=item is_valid
995  
-
996  
-Returns a true/false value as to whether the object currently has enough
997  
-content to be a valid method for a server to publish. This entails having at
998  
-the very least a name, one or more signatures, and a code-reference to route
999  
-the calls to. A server created from the classes in this software suite will
1000  
-not accept a method that is not valid.
1001  
-
1002 952
 =item add_signature(LIST)
1003 953
 
1004 954
 Add one or more signatures (which may be a list reference or a string) to the
9  lib/RPC/XML/Server.pm
@@ -111,7 +111,7 @@ BEGIN
111 111
     );
112 112
 }
113 113
 
114  
-$VERSION = '1.61';
  114
+$VERSION = '1.62';
115 115
 $VERSION = eval $VERSION; ## no critic (ProhibitStringyEval)
116 116
 
117 117
 ###############################################################################
@@ -428,13 +428,6 @@ sub add_method
428 428
             'reference or an object derived from RPC::XML::Procedure';
429 429
     }
430 430
 
431  
-    # Do some sanity-checks
432  
-    if (! $meth->is_valid)
433  
-    {
434  
-        return "$me: Method missing required data; check name, code and/or " .
435  
-            'signature';
436  
-    }
437  
-
438 431
     $self->{__method_table}->{$meth->name} = $meth;
439 432
 
440 433
     return $self;
27  t/30_method.t
@@ -12,7 +12,7 @@ use Test::More;
12 12
 use RPC::XML qw($ALLOW_NIL RPC_INT);
13 13
 use RPC::XML::Procedure;
14 14
 
15  
-plan tests => 76;
  15
+plan tests => 75;
16 16
 
17 17
 ($vol, $dir, undef) = File::Spec->splitpath(File::Spec->rel2abs($0));
18 18
 $dir = File::Spec->catpath($vol, $dir, '');
@@ -31,7 +31,7 @@ $obj = RPC::XML::Procedure->new({ name      => 'test.test',
31 31
                                   code      => sub { $flag = 1; } });
32 32
 isa_ok($obj, 'RPC::XML::Procedure', '$obj');
33 33
 SKIP: {
34  
-    skip 'Cannot test without object', 16
  34
+    skip 'Cannot test without object', 15
35 35
         unless (ref($obj) eq 'RPC::XML::Procedure');
36 36
 
37 37
     # Arguments here don't matter, just testing that trying to call new() on a
@@ -48,7 +48,6 @@ SKIP: {
48 48
     $flag = 0;
49 49
     eval { $obj->code->(); };
50 50
     ok((! $@) && $flag, 'Calling the code');
51  
-    ok($obj->is_valid(), 'Test is_valid() method');
52 51
 
53 52
     # What about the missing values?
54 53
     is($obj->help(),      '', 'Null value for help()');
@@ -96,7 +95,7 @@ $obj = RPC::XML::Procedure->new(
96 95
 );
97 96
 isa_ok($obj, 'RPC::XML::Procedure', '$obj<2>');
98 97
 SKIP: {
99  
-    skip 'Cannot test without object', 3
  98
+    skip 'Cannot test without object', 2
100 99
         unless (ref($obj) eq 'RPC::XML::Procedure');
101 100
 
102 101
     ok(($obj->name() eq 'test.test') &&
@@ -107,7 +106,6 @@ SKIP: {
107 106
        'Basic accessors <2>');
108 107
     $flag = eval { $obj->code->(); };
109 108
     ok((! $@) && $flag, 'Calling the code <2>');
110  
-    ok($obj->is_valid(), 'Test is_valid() method <2>');
111 109
 }
112 110
 
113 111
 # This should succeed, but "hidden" is false because the second overrides the
@@ -123,17 +121,29 @@ $obj = RPC::XML::Procedure->new(
123 121
 isa_ok($obj, 'RPC::XML::Procedure', '$obj<3>');
124 122
 is($obj->hidden(), 0, 'hidden() is correctly false');
125 123
 
  124
+# This should fail due to missing name
  125
+$obj = RPC::XML::Procedure->new({ code => sub { 1; } });
  126
+like($obj, qr/Missing required data \(name or code\)/,
  127
+     'Correct constructor failure [1]');
  128
+
  129
+# This should fail due to missing code
  130
+$obj = RPC::XML::Procedure->new({ name => 'test.test1' });
  131
+like($obj, qr/Missing required data \(name or code\)/,
  132
+     'Correct constructor failure [2]');
  133
+
126 134
 # This should fail due to missing information (the signature)
127 135
 $obj = RPC::XML::Method->new({ name => 'test.test2',
128 136
                                code => sub { $flag = 2; } });
129  
-ok(! ref($obj), 'Correct constructor failure [1]');
  137
+like($obj, qr/Missing required data \(signatures\)/,
  138
+     'Correct constructor failure [3]');
130 139
 
131 140
 # This one fails because the signatures have a collision
132 141
 $obj = RPC::XML::Method->new({ name      => 'test.test2',
133 142
                                signature => [ 'int int',
134 143
                                               'string int' ],
135 144
                                code      => sub { $flag = 2; } });
136  
-ok(! ref($obj), 'Correct constructor failure [2]');
  145
+like($obj, qr/two different return values for one set of params/,
  146
+     'Correct constructor failure [4]');
137 147
 
138 148
 # This file will not load due to missing required information
139 149
 $obj = RPC::XML::Method->new(File::Spec->catfile($dir, 'meth_bad_1.xpl'));
@@ -249,10 +259,9 @@ isa_ok($obj, 'RPC::XML::Function', '$obj');
249 259
 # With this later object, test some of the routines that are overridden in
250 260
 # RPC::XML::Function:
251 261
 SKIP: {
252  
-    skip 'Cannot test without RPC::XML::Function object', 6
  262
+    skip 'Cannot test without RPC::XML::Function object', 5
253 263
         if (ref($obj) ne 'RPC::XML::Function');
254 264
 
255  
-    ok($obj->is_valid, 'RPC::XML::Function passed is_valid test');
256 265
     ok((ref($obj->signature) eq 'ARRAY' && (@{$obj->signature} == 1)),
257 266
        'RPC::XML::Function valid return from signature() <1>');
258 267
     is($obj->add_signature('int int'), $obj,
1  t/meth_good_3.xpl
@@ -3,7 +3,6 @@
3 3
 <functiondef>
4 4
 <name>test.rpc.xml.function</name>
5 5
 <version>1.0</version>
6  
-<signature>string</signature>
7 6
 <help>Simple test method for RPC::XML::Function class</help>
8 7
 <code language="perl">sub test { $_[0] }</code>
9 8
 </functiondef>

0 notes on commit ffb4ccf

Please sign in to comment.
Something went wrong with that request. Please try again.