package XMLMethod; use Server; use RPC::XML::Procedure; sub import { my $child = shift; print "Child is $child\n"; return if $child eq 'XMLMethod'; my $export_procedures = *{"$child\::export_procedures"}{CODE}; die "$child does not implement export_procedures method\n" unless $export_procedures; #run the code my $import_proc = &$export_procedures; my @procedures; while (my ($identifier, $details) = each(%{$import_proc}) ) { my $sub_ref = $details->[0]; my $sig = $details->[1]; my $proc = RPC::XML::Procedure->new({ 'name' => $identifier, 'code' => $sub_ref, 'signature' => [$sig] }); push(@procedures,$proc); } foreach (@procedures) { $Server::server->add_method($_); } } 1; #### package API::Math; use base XMLMethod; sub export_procedures { my %subs = ( 'math.sum' => [\&API::Math::sum, 'int int int'] ); return \%subs; } sub sum{ my $x = shift; my $y = shift; return $y + $x; } 1;