Net-Hadoop-WebHDFS-LWP

 view release on metacpan or  search on metacpan

lib/Net/Hadoop/WebHDFS/LWP.pm  view on Meta::CPAN

package Net::Hadoop::WebHDFS::LWP;
$Net::Hadoop::WebHDFS::LWP::VERSION = '0.012';
use strict;
use warnings;
use parent 'Net::Hadoop::WebHDFS';

# VERSION

use LWP::UserAgent;
use Carp;
use Ref::Util    qw( is_arrayref );
use Scalar::Util qw( openhandle );
use HTTP::Request::StreamingUpload;

use constant UA_PASSTHROUGH_OPTIONS => qw(
    cookie_jar
    env_proxy
    no_proxy
    proxy
);

sub new {
    my $class   = shift;
    my %options = @_;
    my $debug   = delete $options{debug} || 0;
    my $use_ssl = delete $options{use_ssl} || 0;

    require Data::Dumper if $debug;

    my $self = $class->SUPER::new(@_);

    # we don't need Furl
    delete $self->{furl};

    $self->{debug} = $debug;

    # default timeout is a bit short, raise it
    $self->{timeout}   = $options{timeout}   || 30;

    # For filehandle upload support
    $self->{chunksize} = $options{chunksize} || 4096;

    $self->{ua_opts} = {
        map {
            exists $options{$_} ? (
                $_ => $options{ $_ }
            ) : ()
        } UA_PASSTHROUGH_OPTIONS
    };

    $self->_create_ua;

    $self->{use_ssl} = $use_ssl;

    return $self;
}

# Code below copied and modified for LWP from Net::Hadoop::WebHDFS
#
sub request {
    my ( $self, $host, $port, $method, $path, $op, $params, $payload, $header ) = @_;

    my $request_path = $op ? $self->build_path( $path, $op, %$params ) : $path;

    my $protocol = $self->{use_ssl} ? 'https' : 'http';

    # Note: ugly things done with URI, which is already used in the parent
    # module. So we re-parse the path produced there. yuk.
    my $uri = URI->new( $request_path, $protocol );

    $uri->host($host);



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