Shipment

 view release on metacpan or  search on metacpan

lib/Shipment/SOAP/WSDL.pm  view on Meta::CPAN

  
  Generate data classes. Defaults to 1 (true)
  
  =item * silent
  
  Don't tell what's being generated. Defaults to 0 (false)
  
  =back
  
  =item * Less frequently used options for the generation process
  
  =over 8
  
  =item * use_typemap
  
  Generate a typemap based parser. This option is only for compatibility with
  2.00.xx versions and should not be used in any other case. Defaults to 0
  (false)
  
  =item * typemap_include
  
  Code snippet to include in typemap. This option is only for compatibility with
  2.00.xx versions and should not be used in any other case. Defaults to q{}
  (empty string)
  
  =item * attribute_prefix
  
  Individual attribute prefix. Defaults to "$prefix\Attributes"
  
  =item * interface_prefix
  
  Individual (client) interface prefix. Defaults to "$prefix\Interfaces"
  
  =item * server_prefix
  
  Individual server prefix. Defaults to "$prefix\Server"
  
  =item * type_prefix
  
  Individual (data) type prefix. Defaults to "$prefix\Types"
  
  =item * element_prefix
  
  Individual (data) element prefix. Defaults to "$prefix\Elements"
  
  =item * typemap_prefix
  
  Individual typemap prefix. Defaults to "$prefix\Typemaps"
  
  =back
  
  =item * Options controlling LWP::UserAgent
  
  Use of these options is strongly discouraged for published distributions, as
  it may make the distribution dependent on your environment
  
  =over 8
  
  =item * proxy
  
  HTTP(s) proxy to use. Proxies can also be set ussing the HTTP_PROXY and
  HTTPS_PROXY environment variables, which is generally a better choice for build
  scripts.
  
  =item * keepalive
  
  Keppalive is only required in combination with NTLM authentication. It is not
  recommended to create distributions which rely on protected documents, so
  it's somewhat useless for use in Build scripts.
  
  =back
  
  =back
  
  =head1 Build targets
  
  =head2 build
  
  SOAP::WSDL::Build modifies the standard "build" target (invoked when running
  "perl Build") to include the target "webservice".
  
  =cut
  
      sub ACTION_build {
          my $self = shift;
          $self->depends_on('code');
          $self->depends_on('webservice');
          $self->depends_on('docs');
      }
  
  =pod
  
  =head2 webservice
  
  SOAP::WSDL::Build adds the new target webservice. This build target generates
  perl classes from the WSDL definitions specified.
  
  You may run this step separately by calling
  
   perl Build webservice
  
  =cut
  
      sub ACTION_webservice {
          my $self = shift;
          $self->read_config();
          my $config = $self->{properties}->{wsdl2perl};
          warn "No wsdl2perl config key found in Build.PL ",
            "- did you forget to add one?\n"
            if not defined $config;
          $config = [$config] if ref $config ne 'ARRAY';
  
          my %default_config = (
              base_path => 'blib/lib',
              generator => 'XSD',
              silent    => 0,
  
              client => 1,
              server => 0,
              types  => 1,
  
              keep_alive => 0,
              proxy      => q{},
  
              typemap_include => q{},
              use_typemap     => 0,
  
              prefix           => q{My},
              attribute_prefix => q{},
              interface_prefix => q{},
              server_prefix    => q{},
              type_prefix      => q{},
              element_prefix   => q{},
              typemap_prefix   => q{},
          );
  
          foreach my $wsdl_config ( @{$config} ) {
  
              # the easiest way to merge two sets is
              # to just create a new set...
              $self->wsdl2perl( %default_config, %{$wsdl_config} );
          }
      }
  
  =pod
  
  =head1 METHODS
  
  =head2 wsdl2perl
  
   $builder->wsdl2perl(%config);
  
  =cut
  
      sub wsdl2perl {
          my $self = shift;
          my %opt  = @_;
  
          # resolve the default prefix options
          # If only prefix is given
          # and interface_prefix has not been set explicitely
          # make it "$prefix\Interfaces"
          map {
              my $opt_key = $_;
              if (
                  $opt_key =~ / (\w+) _prefix $/xms    # relevant option
                  && !$opt{$opt_key}   # that hasn't already been explicitly set
                ) {
                  my $prefix_type = $1;
                  $opt{$opt_key} = $opt{prefix} .    # My
                    ucfirst($prefix_type) .          # Typemap
                    ( $prefix_type eq 'server' ? '' : 's' );    # s
              }
          } keys %opt;
  
          # set environment proxies if given
          # makes sure existing environment proxies are regarded unless
          # overridden...
          local $ENV{HTTP_PROXY}  = $opt{proxy} if $opt{proxy};
          local $ENV{HTTPS_PROXY} = $opt{proxy} if $opt{proxy};
  
          my $lwp = LWP::UserAgent->new(
              $opt{keep_alive}
              ? ( keep_alive => 1 )
              : () );
          $lwp->env_proxy()
            ;    # get proxy from environment. Works for both http & https.
          $lwp->agent(qq[SOAP::WSDL $SOAP::WSDL::Expat::WSDLParser::VERSION]);
  
          my $parser =
            SOAP::WSDL::Expat::WSDLParser->new( {user_agent => $lwp,} );
  
          my $uri;
          if (-e $opt{location}) {
              $uri = URI::file->new_abs( $opt{location} );
          }
          else {
              warn "wsdl file $opt{location} not found\n"
                  if ($opt{location} !~m{https?://}x);
              $uri = URI->new($opt{location});
          }
  
  
          my $definitions = $parser->parse_uri($uri);
  
          my %typemap = ();
          if ( $opt{typemap_include} ) {
              die "$opt{typemap_include} not found "
                if not -f $opt{typemap_include};
              %typemap = do $opt{typemap_include};
          }
  
          my $generator = SOAP::WSDL::Factory::Generator->get_generator(
              {type => $opt{'generator'}} );
  
          if (%typemap) {
              if ( $generator->can('set_typemap') ) {
                  $generator->set_typemap( \%typemap );
              }
              else {
                  warn "Typemap snippet given, but ",
                    "generator does not support it\n";
              }
          }
  
          $generator->set_attribute_prefix( $opt{attribute_prefix} )
            if $generator->can('set_attribute_prefix');
          $generator->set_type_prefix( $opt{type_prefix} )
            if $generator->can('set_type_prefix');
          $generator->set_typemap_prefix( $opt{typemap_prefix} )
            if $generator->can('set_typemap_prefix');
          $generator->set_element_prefix( $opt{element_prefix} )
            if $generator->can('set_element_prefix');
          $generator->set_interface_prefix( $opt{interface_prefix} )
            if $generator->can('set_interface_prefix');
          $generator->set_server_prefix( $opt{server_prefix} )
            if $generator->can('set_server_prefix');
  
          $generator->set_OUTPUT_PATH( $opt{base_path} )



( run in 0.657 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )