Bundle-WATERKIP

 view release on metacpan or  search on metacpan

bin/opnpost  view on Meta::CPAN

}
elsif ($options{help}) {
    pod2usage({-verbose => 1});
}

my $missing;
foreach (@required) {
    if (!$options{$_}) {
        $missing = 1;
        warn "Required option $_ missing\n";
    }
}
if ($missing) {
    print STDERR "\n";
    pod2usage({-verbose => 1, -exit => 1});
}

my $content = scalar io->catfile($options{content})->slurp;

if ($options{'wrap-soap'}) {
    $content = _soap_envelope($content);

}

my $ua = LWP::UserAgent->new(
    agent                 => $options{agent} // "How-about-no/-1",
    cookie_jar            => HTTP::Cookies->new(),
    protocols_allowed     => [qw(https http)],
    timeout               => $options{timeout},
    requests_redirectable => $options{redir} // [qw(GET HEAD)],
    ssl_opts              => {
        $options{k} ? (verify_hostname => 0, SSL_verify_mode => 0) : (),
        $options{ca} ? (SSL_ca_file => $options{ca})
        : (SSL_ca_path => $options{'ca-path'}),
        $options{cc}
        ? (
            SSL_cert_file => $options{cc},
            SSL_key_file  => $options{cc}
            )
        : ()
    }
);

my $req = HTTP::Request->new(
    $options{X} => $options{endpoint},
    HTTP::Headers->new(
        Content_Type => $options{'content-type'},
        exists $options{'soap-action'} ?
        ( SOAPAction   => sprintf('"%s"', $options{'soap-action'}) ) : (),
    ),
    $content,
);

my $res = $ua->request($req);
if ($res->is_success) {

    if ($options{v}) {
        print $req->as_string, $/, $res->as_string, $/;
    }
    else {
        print $res->decoded_content, $/;
    }
}
else {
    die $req->as_string, $/, $res->as_string, $/;
}

sub _soap_envelope {
    my ($xml) = @_;


    # Strip the XML decl of the XML if it exists
    $xml = XML::LibXML->load_xml(string => $xml)->findnodes('//*')->[0];

    my $env = "";
    if (defined $options{'soap-version'}  && $options{'soap-version'} == 1.1) {
        $env = q{<?xml version="1.0" encoding="utf-8"?>
    <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
      <soap-env:Body>%s</soap-env:Body>
    </soap-env:Envelope>};
    }
    else {
        $env = q{<?xml version="1.0" encoding="utf-8"?>
    <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
      <soap-env:Body>%s</soap-env:Body>
    </soap-env:Envelope>};

    }
    return sprintf($env, $xml);
}

__END__

=pod

=encoding UTF-8

=head1 NAME

opnpost - A OPN User agent that post stuf

=head1 VERSION

version 0.003

=head1 SYNOPSIS

opnpost opnjson opnsoap OPTIONS

=head1 DESCRIPTION

opnpost is a generic useragent that posts data to a particual endpoint.
It is basicly wget or curl, but only for POSTING data.
opnsoap is a client for posting SOAP and opnjson is a client for posting JSON

=head1 NAME

opnpost opnjson opnsoap - A OPN UA poster boy object

=head1 OPTIONS



( run in 0.592 second using v1.01-cache-2.11-cpan-39bf76dae61 )