From dev-return-53589-archive-asf-public=cust-asf.ponee.io@thrift.apache.org Thu Oct 18 01:14:14 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 1FE4518061A for ; Thu, 18 Oct 2018 01:14:11 +0200 (CEST) Received: (qmail 53769 invoked by uid 500); 17 Oct 2018 23:14:11 -0000 Mailing-List: contact dev-help@thrift.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@thrift.apache.org Delivered-To: mailing list dev@thrift.apache.org Received: (qmail 53758 invoked by uid 99); 17 Oct 2018 23:14:11 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Oct 2018 23:14:11 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 8FC541A1A47 for ; Wed, 17 Oct 2018 23:14:10 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -109.5 X-Spam-Level: X-Spam-Status: No, score=-109.5 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id x76Zn1J1HJx6 for ; Wed, 17 Oct 2018 23:14:03 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id E45825F52B for ; Wed, 17 Oct 2018 23:14:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 0C38FE13DA for ; Wed, 17 Oct 2018 23:14:01 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id C0AB621250 for ; Wed, 17 Oct 2018 23:14:00 +0000 (UTC) Date: Wed, 17 Oct 2018 23:14:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: dev@thrift.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (THRIFT-4382) Replace the use of Perl Indirect Object Syntax calls to new() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/THRIFT-4382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16654351#comment-16654351 ] ASF GitHub Bot commented on THRIFT-4382: ---------------------------------------- jeking3 closed pull request #1613: THRIFT-4382: Replace the use of Indirect Object Syntax calls to new() URL: https://github.com/apache/thrift/pull/1613 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/compiler/cpp/src/thrift/generate/t_perl_generator.cc b/compiler/cpp/src/thrift/generate/t_perl_generator.cc index 5a308cfea1..8924a76001 100644 --- a/compiler/cpp/src/thrift/generate/t_perl_generator.cc +++ b/compiler/cpp/src/thrift/generate/t_perl_generator.cc @@ -354,7 +354,7 @@ string t_perl_generator::render_const_value(t_type* type, t_const_value* value) } else if (type->is_enum()) { out << value->get_integer(); } else if (type->is_struct() || type->is_xception()) { - out << "new " << perl_namespace(type->get_program()) << type->get_name() << "({" << endl; + out << perl_namespace(type->get_program()) << type->get_name() << "->new({" << endl; indent_up(); const vector& fields = ((t_struct*)type)->get_members(); @@ -546,7 +546,7 @@ void t_perl_generator::generate_perl_struct_reader(ostream& out, t_struct* tstru indent(out) << "$xfer += $input->readStructBegin(\\$fname);" << endl; // Loop over reading in fields - indent(out) << "while (1) " << endl; + indent(out) << "while (1)" << endl; scope_up(out); @@ -758,7 +758,7 @@ void t_perl_generator::generate_service_processor(t_service* tservice) { f_service_ << indent() << "$input->skip(Thrift::TType::STRUCT);" << endl << indent() << "$input->readMessageEnd();" << endl << indent() - << "my $x = new Thrift::TApplicationException('Function '.$fname.' not implemented.', " + << "my $x = Thrift::TApplicationException->new('Function '.$fname.' not implemented.', " "Thrift::TApplicationException::UNKNOWN_METHOD);" << endl << indent() << "$output->writeMessageBegin($fname, Thrift::TMessageType::EXCEPTION, $rseqid);" << endl << indent() << "$x->write($output);" << endl << indent() @@ -798,7 +798,7 @@ void t_perl_generator::generate_process_function(t_service* tservice, t_function string resultname = perl_namespace(tservice->get_program()) + service_name_ + "_" + tfunction->get_name() + "_result"; - f_service_ << indent() << "my $args = new " << argsname << "();" << endl << indent() + f_service_ << indent() << "my $args = " << argsname << "->new();" << endl << indent() << "$args->read($input);" << endl; f_service_ << indent() << "$input->readMessageEnd();" << endl; @@ -809,7 +809,7 @@ void t_perl_generator::generate_process_function(t_service* tservice, t_function // Declare result for non oneway function if (!tfunction->is_oneway()) { - f_service_ << indent() << "my $result = new " << resultname << "();" << endl; + f_service_ << indent() << "my $result = " << resultname << "->new();" << endl; } // Try block for a function with exceptions @@ -858,7 +858,7 @@ void t_perl_generator::generate_process_function(t_service* tservice, t_function f_service_ << indent() << "if ($@) {" << endl; indent_up(); f_service_ << indent() << "$@ =~ s/^\\s+|\\s+$//g;" << endl - << indent() << "my $err = new Thrift::TApplicationException(\"Unexpected Exception: \" . $@, Thrift::TApplicationException::INTERNAL_ERROR);" << endl + << indent() << "my $err = Thrift::TApplicationException->new(\"Unexpected Exception: \" . $@, Thrift::TApplicationException::INTERNAL_ERROR);" << endl << indent() << "$output->writeMessageBegin('" << tfunction->get_name() << "', Thrift::TMessageType::EXCEPTION, $seqid);" << endl << indent() << "$err->write($output);" << endl << indent() << "$output->writeMessageEnd();" << endl @@ -1106,7 +1106,7 @@ void t_perl_generator::generate_service_client(t_service* tservice) { << "', " << ((*f_iter)->is_oneway() ? "Thrift::TMessageType::ONEWAY" : "Thrift::TMessageType::CALL") << ", $self->{seqid});" << endl; - f_service_ << indent() << "my $args = new " << argsname << "();" << endl; + f_service_ << indent() << "my $args = " << argsname << "->new();" << endl; for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) { f_service_ << indent() << "$args->{" << (*fld_iter)->get_name() << "} = $" @@ -1140,12 +1140,12 @@ void t_perl_generator::generate_service_client(t_service* tservice) { f_service_ << indent() << "$self->{input}->readMessageBegin(\\$fname, \\$mtype, \\$rseqid);" << endl << indent() << "if ($mtype == Thrift::TMessageType::EXCEPTION) {" << endl - << indent() << " my $x = new Thrift::TApplicationException();" << endl << indent() + << indent() << " my $x = Thrift::TApplicationException->new();" << endl << indent() << " $x->read($self->{input});" << endl << indent() << " $self->{input}->readMessageEnd();" << endl << indent() << " die $x;" << endl << indent() << "}" << endl; - f_service_ << indent() << "my $result = new " << resultname << "();" << endl << indent() + f_service_ << indent() << "my $result = " << resultname << "->new();" << endl << indent() << "$result->read($self->{input});" << endl; f_service_ << indent() << "$self->{input}->readMessageEnd();" << endl << endl; @@ -1586,7 +1586,7 @@ string t_perl_generator::declare_field(t_field* tfield, bool init, bool obj) { result += " = []"; } else if (type->is_struct() || type->is_xception()) { if (obj) { - result += " = new " + perl_namespace(type->get_program()) + type->get_name() + "()"; + result += " = " + perl_namespace(type->get_program()) + type->get_name() + "->new()"; } else { result += " = undef"; } diff --git a/lib/perl/lib/Thrift/BinaryProtocol.pm b/lib/perl/lib/Thrift/BinaryProtocol.pm index 61937e4d99..d62509a561 100644 --- a/lib/perl/lib/Thrift/BinaryProtocol.pm +++ b/lib/perl/lib/Thrift/BinaryProtocol.pm @@ -39,7 +39,7 @@ use version 0.77; our $VERSION = version->declare("$Thrift::VERSION"); use constant VERSION_MASK => 0xffff0000; use constant VERSION_1 => 0x80010000; -use constant IS_BIG_ENDIAN => unpack("h*", pack("s", 1)) =~ /01/; +use constant IS_BIG_ENDIAN => unpack('h*', pack('s', 1)) =~ m/01/; sub new { @@ -67,7 +67,8 @@ sub writeMessageEnd return 0; } -sub writeStructBegin{ +sub writeStructBegin +{ my $self = shift; my $name = shift; return 0; @@ -253,7 +254,7 @@ sub readMessageBegin my $result = $self->readI32(\$version); if (($version & VERSION_MASK) > 0) { if (($version & VERSION_MASK) != VERSION_1) { - die new Thrift::TProtocolException('Missing version identifier', + die Thrift::TProtocolException->new('Missing version identifier', Thrift::TProtocolException::BAD_VERSION); } $$type = $version & 0x000000ff; @@ -261,7 +262,8 @@ sub readMessageBegin $result + $self->readString($name) + $self->readI32($seqid); - } else { # old client support code + } + else { # old client support code return $result + $self->readStringBody($name, $version) + # version here holds the size of the string @@ -427,7 +429,7 @@ sub readI64 my ($hi,$lo)=unpack('NN',$data); - my $vec = new Bit::Vector(64); + my $vec = Bit::Vector->new(64); $vec->Chunk_Store(32,32,$hi); $vec->Chunk_Store(32,0,$lo); @@ -467,7 +469,8 @@ sub readString if ($len) { $$value = $self->{trans}->readAll($len); - } else { + } + else { $$value = ''; } @@ -482,7 +485,8 @@ sub readStringBody if ($len) { $$value = $self->{trans}->readAll($len); - } else { + } + else { $$value = ''; } @@ -508,7 +512,7 @@ sub getProtocol{ my $self = shift; my $trans = shift; - return new Thrift::BinaryProtocol($trans); + return Thrift::BinaryProtocol->new($trans); } 1; diff --git a/lib/perl/lib/Thrift/Exception.pm b/lib/perl/lib/Thrift/Exception.pm index 5f0d8fb7f7..e4040689cc 100644 --- a/lib/perl/lib/Thrift/Exception.pm +++ b/lib/perl/lib/Thrift/Exception.pm @@ -29,11 +29,10 @@ use version 0.77; our $VERSION = version->declare("$Thrift::VERSION"); use overload '""' => sub { return - ref( $_[0] ) - . " error: " - . ( $_[0]->{message} || 'empty message' ) - . " (code " - . ( defined $_[0]->{code} ? $_[0]->{code} : 'undefined' ) . ")"; + sprintf '%s error: %s (code %s)', + ref( $_[0] ), + ( $_[0]->{message} || 'empty message' ), + ( defined $_[0]->{code} ? $_[0]->{code} : 'undefined' ); }; sub new { @@ -91,7 +90,8 @@ sub read { if ($ftype == Thrift::TType::STRING) { $xfer += $input->readString(\$self->{message}); - } else { + } + else { $xfer += $input->skip($ftype); } @@ -101,7 +101,8 @@ sub read { /2/ && do{ if ($ftype == Thrift::TType::I32) { $xfer += $input->readI32(\$self->{code}); - } else { + } + else { $xfer += $input->skip($ftype); } last; diff --git a/lib/perl/lib/Thrift/FramedTransport.pm b/lib/perl/lib/Thrift/FramedTransport.pm index ee842e61a4..ba89ba3e0f 100644 --- a/lib/perl/lib/Thrift/FramedTransport.pm +++ b/lib/perl/lib/Thrift/FramedTransport.pm @@ -70,7 +70,7 @@ sub close my $self = shift; if (defined $self->{transport}) { - $self->{transport}->close(); + $self->{transport}->close(); } } diff --git a/lib/perl/lib/Thrift/HttpClient.pm b/lib/perl/lib/Thrift/HttpClient.pm index 6e6a63193a..40ec9ce204 100644 --- a/lib/perl/lib/Thrift/HttpClient.pm +++ b/lib/perl/lib/Thrift/HttpClient.pm @@ -61,7 +61,7 @@ sub setTimeout sub setRecvTimeout { - warn "setRecvTimeout is deprecated - use setTimeout instead"; + warn 'setRecvTimeout is deprecated - use setTimeout instead'; # note: recvTimeout was never used so we do not need to do anything here } @@ -70,7 +70,7 @@ sub setSendTimeout my $self = shift; my $timeout = shift; - warn "setSendTimeout is deprecated - use setTimeout instead"; + warn 'setSendTimeout is deprecated - use setTimeout instead'; $self->setTimeout($timeout); } @@ -102,8 +102,8 @@ sub close { my $self = shift; if (defined($self->{io})) { - close($self->{io}); - $self->{io} = undef; + close($self->{io}); + $self->{io} = undef; } } @@ -121,7 +121,7 @@ sub readAll my $buf = $self->read($len); if (!defined($buf)) { - die new Thrift::TTransportException("TSocket: Could not read $len bytes from input buffer", + die Thrift::TTransportException->new("TSocket: Could not read $len bytes from input buffer", Thrift::TTransportException::END_OF_FILE); } return $buf; @@ -140,17 +140,18 @@ sub read my $in = $self->{in}; if (!defined($in)) { - die new Thrift::TTransportException("Response buffer is empty, no request.", + die Thrift::TTransportException->new('Response buffer is empty, no request.', Thrift::TTransportException::END_OF_FILE); } eval { - my $ret = sysread($in, $buf, $len); - if (! defined($ret)) { - die new Thrift::TTransportException("No more data available.", + my $ret = sysread($in, $buf, $len); + if (! defined($ret)) { + die Thrift::TTransportException->new('No more data available.', Thrift::TTransportException::TIMED_OUT); - } - }; if($@){ - die new Thrift::TTransportException("$@", Thrift::TTransportException::UNKNOWN); + } + }; + if($@){ + die Thrift::TTransportException->new("$@", Thrift::TTransportException::UNKNOWN); } return $buf; @@ -173,8 +174,9 @@ sub flush { my $self = shift; - my $ua = LWP::UserAgent->new('timeout' => ($self->{timeout} / 1000), - 'agent' => 'Perl/THttpClient' + my $ua = LWP::UserAgent->new( + 'timeout' => ($self->{timeout} / 1000), + 'agent' => 'Perl/THttpClient' ); $ua->default_header('Accept' => 'application/x-thrift'); $ua->default_header('Content-Type' => 'application/x-thrift'); @@ -184,8 +186,7 @@ sub flush $out->setpos(0); # rewind my $buf = join('', <$out>); - my $request = new HTTP::Request(POST => $self->{url}, undef, $buf); - map { $request->header($_ => $self->{headers}->{$_}) } keys %{$self->{headers}}; + my $request = HTTP::Request->new(POST => $self->{url}, ($self->{headers} || undef), $buf); my $response = $ua->request($request); my $content_ref = $response->content_ref; diff --git a/lib/perl/lib/Thrift/MemoryBuffer.pm b/lib/perl/lib/Thrift/MemoryBuffer.pm index 1e51239295..be97ce4f8e 100644 --- a/lib/perl/lib/Thrift/MemoryBuffer.pm +++ b/lib/perl/lib/Thrift/MemoryBuffer.pm @@ -35,10 +35,10 @@ sub new my $bufferSize= shift || 1024; my $self = { - buffer => '', - bufferSize=> $bufferSize, - wPos => 0, - rPos => 0, + buffer => '', + bufferSize => $bufferSize, + wPos => 0, + rPos => 0, }; return bless($self,$classname); @@ -117,7 +117,7 @@ sub readAll my $avail = ($self->{wPos} - $self->{rPos}); if ($avail < $len) { - die new TTransportException("Attempt to readAll($len) found only $avail available", + die TTransportException->new("Attempt to readAll($len) found only $avail available", Thrift::TTransportException::END_OF_FILE); } diff --git a/lib/perl/lib/Thrift/MultiplexedProcessor.pm b/lib/perl/lib/Thrift/MultiplexedProcessor.pm index 05c4ead9c2..ae925d7cd9 100644 --- a/lib/perl/lib/Thrift/MultiplexedProcessor.pm +++ b/lib/perl/lib/Thrift/MultiplexedProcessor.pm @@ -101,32 +101,32 @@ sub process { $input->readMessageBegin(\$fname, \$mtype, \$rseqid); if ($mtype ne Thrift::TMessageType::CALL && $mtype ne Thrift::TMessageType::ONEWAY) { - die new Thrift::TException("This should not have happened!?"); + die Thrift::TException->new('This should not have happened!?'); } # Extract the service name and the new Message name. if (index($fname, Thrift::MultiplexedProtocol::SEPARATOR) == -1) { if (defined $self->{defaultProcessor}) { return $self->{defaultProcessor}->process( - new Thrift::StoredMessageProtocol($input, $fname, $mtype, $rseqid), $output + Thrift::StoredMessageProtocol->new($input, $fname, $mtype, $rseqid), $output ); } else { - die new Thrift::TException("Service name not found in message name: {$fname} and no default processor defined. Did you " . - "forget to use a MultiplexProtocol in your client?"); + die Thrift::TException->new("Service name not found in message name: {$fname} and no default processor defined. Did you " . + 'forget to use a MultiplexProtocol in your client?'); } } (my $serviceName, my $messageName) = split(':', $fname, 2); if (!exists($self->{serviceProcessorMap}->{$serviceName})) { - die new Thrift::TException("Service name not found: {$serviceName}. Did you forget " . - "to call registerProcessor()?"); + die Thrift::TException->new("Service name not found: {$serviceName}. Did you forget " . + 'to call registerProcessor()?'); } # Dispatch processing to the stored processor my $processor = $self->{serviceProcessorMap}->{$serviceName}; return $processor->process( - new Thrift::StoredMessageProtocol($input, $messageName, $mtype, $rseqid), $output + Thrift::StoredMessageProtocol->new($input, $messageName, $mtype, $rseqid), $output ); } diff --git a/lib/perl/lib/Thrift/MultiplexedProtocol.pm b/lib/perl/lib/Thrift/MultiplexedProtocol.pm index 903211f107..5b5b60bc7d 100644 --- a/lib/perl/lib/Thrift/MultiplexedProtocol.pm +++ b/lib/perl/lib/Thrift/MultiplexedProtocol.pm @@ -53,7 +53,7 @@ sub new { # sub writeMessageBegin { - my $self = shift; + my $self = shift; my ($name, $type, $seqid) = @_; if ($type == Thrift::TMessageType::CALL || $type == Thrift::TMessageType::ONEWAY) { diff --git a/lib/perl/lib/Thrift/Protocol.pm b/lib/perl/lib/Thrift/Protocol.pm index c681f60829..26ef46a00f 100644 --- a/lib/perl/lib/Thrift/Protocol.pm +++ b/lib/perl/lib/Thrift/Protocol.pm @@ -81,14 +81,14 @@ sub getTransport sub writeMessageBegin { my ($name, $type, $seqid); - die "abstract"; + die 'abstract'; } # # Close the message # sub writeMessageEnd { - die "abstract"; + die 'abstract'; } # @@ -101,7 +101,7 @@ sub writeMessageEnd { sub writeStructBegin { my ($name); - die "abstract"; + die 'abstract'; } # @@ -111,7 +111,7 @@ sub writeStructBegin { # @return int How many bytes written # sub writeStructEnd { - die "abstract"; + die 'abstract'; } # @@ -126,79 +126,79 @@ sub writeStructEnd { sub writeFieldBegin { my ($fieldName, $fieldType, $fieldId); - die "abstract"; + die 'abstract'; } sub writeFieldEnd { - die "abstract"; + die 'abstract'; } sub writeFieldStop { - die "abstract"; + die 'abstract'; } sub writeMapBegin { my ($keyType, $valType, $size); - die "abstract"; + die 'abstract'; } sub writeMapEnd { - die "abstract"; + die 'abstract'; } sub writeListBegin { my ($elemType, $size); - die "abstract"; + die 'abstract'; } sub writeListEnd { - die "abstract"; + die 'abstract'; } sub writeSetBegin { my ($elemType, $size); - die "abstract"; + die 'abstract'; } sub writeSetEnd { - die "abstract"; + die 'abstract'; } sub writeBool { my ($bool); - die "abstract"; + die 'abstract'; } sub writeByte { my ($byte); - die "abstract"; + die 'abstract'; } sub writeI16 { my ($i16); - die "abstract"; + die 'abstract'; } sub writeI32 { my ($i32); - die "abstract"; + die 'abstract'; } sub writeI64 { my ($i64); - die "abstract"; + die 'abstract'; } sub writeDouble { my ($dub); - die "abstract"; + die 'abstract'; } sub writeString { my ($str); - die "abstract"; + die 'abstract'; } # @@ -211,7 +211,7 @@ sub writeString sub readMessageBegin { my ($name, $type, $seqid); - die "abstract"; + die 'abstract'; } # @@ -219,105 +219,105 @@ sub readMessageBegin # sub readMessageEnd { - die "abstract"; + die 'abstract'; } sub readStructBegin { my($name); - die "abstract"; + die 'abstract'; } sub readStructEnd { - die "abstract"; + die 'abstract'; } sub readFieldBegin { my ($name, $fieldType, $fieldId); - die "abstract"; + die 'abstract'; } sub readFieldEnd { - die "abstract"; + die 'abstract'; } sub readMapBegin { my ($keyType, $valType, $size); - die "abstract"; + die 'abstract'; } sub readMapEnd { - die "abstract"; + die 'abstract'; } sub readListBegin { my ($elemType, $size); - die "abstract"; + die 'abstract'; } sub readListEnd { - die "abstract"; + die 'abstract'; } sub readSetBegin { my ($elemType, $size); - die "abstract"; + die 'abstract'; } sub readSetEnd { - die "abstract"; + die 'abstract'; } sub readBool { my ($bool); - die "abstract"; + die 'abstract'; } sub readByte { my ($byte); - die "abstract"; + die 'abstract'; } sub readI16 { my ($i16); - die "abstract"; + die 'abstract'; } sub readI32 { my ($i32); - die "abstract"; + die 'abstract'; } sub readI64 { my ($i64); - die "abstract"; + die 'abstract'; } sub readDouble { my ($dub); - die "abstract"; + die 'abstract'; } sub readString { my ($str); - die "abstract"; + die 'abstract'; } # @@ -405,7 +405,7 @@ sub skip return $result; } - die new Thrift::TProtocolException("Type $type not recognized --- corrupt data?", + die Thrift::TProtocolException->new("Type $type not recognized --- corrupt data?", Thrift::TProtocolException::INVALID_DATA); } @@ -424,7 +424,7 @@ sub skipBinary if($type == Thrift::TType::BOOL) { - return $itrans->readAll(1); + return $itrans->readAll(1); } elsif($type == Thrift::TType::BYTE) { @@ -459,17 +459,17 @@ sub skipBinary { my $result = 0; while (1) { - my $ftype = 0; - my $fid = 0; - my $data = $itrans->readAll(1); - my @arr = unpack('c', $data); - $ftype = $arr[0]; - if ($ftype == Thrift::TType::STOP) { - last; - } - # I16 field id - $result += $itrans->readAll(2); - $result += $self->skipBinary($itrans, $ftype); + my $ftype = 0; + my $fid = 0; + my $data = $itrans->readAll(1); + my @arr = unpack('c', $data); + $ftype = $arr[0]; + if ($ftype == Thrift::TType::STOP) { + last; + } + # I16 field id + $result += $itrans->readAll(2); + $result += $self->skipBinary($itrans, $ftype); } return $result; } @@ -517,7 +517,7 @@ sub skipBinary return $result; } - die new Thrift::TProtocolException("Type $type not recognized --- corrupt data?", + die Thrift::TProtocolException->new("Type $type not recognized --- corrupt data?", Thrift::TProtocolException::INVALID_DATA); } @@ -542,7 +542,7 @@ sub new { sub getProtocol { my ($trans); - die "interface"; + die 'interface'; } diff --git a/lib/perl/lib/Thrift/SSLServerSocket.pm b/lib/perl/lib/Thrift/SSLServerSocket.pm index d29671bfe8..7b06431027 100644 --- a/lib/perl/lib/Thrift/SSLServerSocket.pm +++ b/lib/perl/lib/Thrift/SSLServerSocket.pm @@ -48,7 +48,7 @@ sub new sub __client { - return new Thrift::SSLSocket(); + return Thrift::SSLSocket->new(); } sub __listen diff --git a/lib/perl/lib/Thrift/SSLSocket.pm b/lib/perl/lib/Thrift/SSLSocket.pm index 4bdf637292..e34924df4a 100644 --- a/lib/perl/lib/Thrift/SSLSocket.pm +++ b/lib/perl/lib/Thrift/SSLSocket.pm @@ -34,7 +34,7 @@ use version 0.77; our $VERSION = version->declare("$Thrift::VERSION"); # Construction and usage # # my $opts = {} -# my $socket = new Thrift::SSLSocket(\%opts); +# my $socket = Thrift::SSLSocket->new(\%opts); # # options: # diff --git a/lib/perl/lib/Thrift/Server.pm b/lib/perl/lib/Thrift/Server.pm index f265d45f94..28822e8747 100644 --- a/lib/perl/lib/Thrift/Server.pm +++ b/lib/perl/lib/Thrift/Server.pm @@ -51,7 +51,7 @@ sub new if (scalar @args == 2) { - $self = _init($args[0], $args[1], + $self = _init($args[0], $args[1], Thrift::BufferedTransportFactory->new(), Thrift::BufferedTransportFactory->new(), Thrift::BinaryProtocolFactory->new(), @@ -67,7 +67,7 @@ sub new } else { - die new Thrift::TException("Thrift::Server expects exactly 2, 4, or 6 args"); + die Thrift::TException->new('Thrift::Server expects exactly 2, 4, or 6 args'); } return bless($self,$classname); @@ -94,7 +94,7 @@ sub _init sub serve { - die "abstract"; + die 'abstract'; } sub _clientBegin @@ -115,7 +115,7 @@ sub _handleException my $self = shift; my $e = shift; - if ($e->isa("Thrift::TException") and exists $e->{message}) { + if ($e->isa('Thrift::TException') and exists $e->{message}) { my $message = $e->{message}; my $code = $e->{code}; my $out = $code . ':' . $message; @@ -123,10 +123,12 @@ sub _handleException $message =~ m/TTransportException/ and die $out; if ($message =~ m/Socket/) { # suppress Socket messages - } else { + } + else { warn $out; } - } else { + } + else { warn $e; } } @@ -151,7 +153,7 @@ sub serve { my $self = shift; my $stop = 0; - + $self->{serverTransport}->listen(); while (!$stop) { my $client = $self->{serverTransport}->accept(); @@ -166,10 +168,10 @@ sub serve { $self->{processor}->process($iprot, $oprot); } - }; if($@) { + }; + if($@) { $self->_handleException($@); } - $itrans->close(); $otrans->close(); } else { @@ -184,7 +186,7 @@ sub serve # package Thrift::ForkingServer; use parent -norequire, 'Thrift::Server'; -use POSIX ":sys_wait_h"; +use POSIX ':sys_wait_h'; use version 0.77; our $VERSION = version->declare("$Thrift::VERSION"); sub new @@ -231,10 +233,12 @@ sub _client if ($pid) { $self->_parent($pid, $itrans, $otrans); - } else { + } + else { $self->_child($itrans, $otrans, $iprot, $oprot); } - }; if($@) { + }; + if($@) { $self->_handleException($@); } } @@ -267,7 +271,8 @@ sub _child { $self->{processor}->process($iprot, $oprot); } - }; if($@) { + }; + if($@) { $ecode = 1; $self->_handleException($@); } @@ -288,14 +293,16 @@ sub tryClose { $file->close(); } - }; if($@) { - if ($@->isa("Thrift::TException") and exists $@->{message}) { + }; + if($@) { + if ($@->isa('Thrift::TException') and exists $@->{message}) { my $message = $@->{message}; my $code = $@->{code}; my $out = $code . ':' . $message; warn $out; - } else { + } + else { warn $@; } } diff --git a/lib/perl/lib/Thrift/ServerSocket.pm b/lib/perl/lib/Thrift/ServerSocket.pm index 2c4d906c47..39726438b5 100644 --- a/lib/perl/lib/Thrift/ServerSocket.pm +++ b/lib/perl/lib/Thrift/ServerSocket.pm @@ -38,7 +38,7 @@ use version 0.77; our $VERSION = version->declare("$Thrift::VERSION"); # @param[in] host host interface to listen on (undef = all interfaces) # @param[in] port port number to listen on (required) # @param[in] queue the listen queue size (default if not specified is 128) -# @example my $serversock = new Thrift::ServerSocket(host => undef, port => port) +# @example my $serversock = Thrift::ServerSocket->new(host => undef, port => port) # sub new { @@ -49,7 +49,8 @@ sub new # Support both old-style "port number" construction and newer... if (ref($args) eq 'HASH') { $self = $args; - } else { + } + else { $self = { port => $args }; } @@ -71,7 +72,7 @@ sub listen $self->{debugHandler}->($error); } - die new Thrift::TTransportException($error, Thrift::TTransportException::NOT_OPEN); + die Thrift::TTransportException->new($error, Thrift::TTransportException::NOT_OPEN); }; $self->{handle} = $sock; @@ -84,7 +85,7 @@ sub accept if ( exists $self->{handle} and defined $self->{handle} ) { my $client = $self->{handle}->accept(); my $result = $self->__client(); - $result->{handle} = new IO::Select($client); + $result->{handle} = IO::Select->new($client); return $result; } @@ -93,12 +94,12 @@ sub accept sub close { - my $self = shift; - + my $self = shift; + if ( exists $self->{handle} and defined $self->{handle} ) { $self->{handle}->close(); - } + } } ### @@ -107,7 +108,7 @@ sub close sub __client { - return new Thrift::Socket(); + return Thrift::Socket->new(); } sub __listen diff --git a/lib/perl/lib/Thrift/Socket.pm b/lib/perl/lib/Thrift/Socket.pm index ae248df8ab..ba0db5eb4e 100644 --- a/lib/perl/lib/Thrift/Socket.pm +++ b/lib/perl/lib/Thrift/Socket.pm @@ -36,7 +36,7 @@ use version 0.77; our $VERSION = version->declare("$Thrift::VERSION"); # Construction and usage # # my $opts = {} -# my $socket = new Thrift::Socket(\%opts); +# my $socket = Thrift::Socket->new(\%opts); # # options: # @@ -120,10 +120,10 @@ sub open my $sock = $self->__open() || do { my $error = ref($self).': Could not connect to '.$self->{host}.':'.$self->{port}.' ('.$!.')'; - die new Thrift::TTransportException($error, Thrift::TTransportException::NOT_OPEN); + die Thrift::TTransportException->new($error, Thrift::TTransportException::NOT_OPEN); }; - $self->{handle} = new IO::Select( $sock ); + $self->{handle} = IO::Select->new( $sock ); } # @@ -159,15 +159,17 @@ sub readAll if (!defined $buf || $buf eq '') { - die new Thrift::TTransportException(ref($self).': Could not read '.$len.' bytes from '. + die Thrift::TTransportException->new(ref($self).': Could not read '.$len.' bytes from '. $self->{host}.':'.$self->{port}, Thrift::TTransportException::END_OF_FILE); - } elsif ((my $sz = length($buf)) < $len) { + } + elsif ((my $sz = length($buf)) < $len) { $pre .= $buf; $len -= $sz; - } else { + } + else { return $pre.$buf; } } @@ -191,7 +193,7 @@ sub read if (!defined $buf || $buf eq '') { - die new Thrift::TTransportException(ref($self).': Could not read '.$len.' bytes from '. + die Thrift::TTransportException->new(ref($self).': Could not read '.$len.' bytes from '. $self->{host}.':'.$self->{port}, Thrift::TTransportException::END_OF_FILE); } @@ -217,7 +219,7 @@ sub write my @sockets = $self->{handle}->can_write( $self->{sendTimeout} / 1000 ); if(@sockets == 0){ - die new Thrift::TTransportException(ref($self).': timed out writing to bytes from '. + die Thrift::TTransportException->new(ref($self).': timed out writing to bytes from '. $self->{host}.':'.$self->{port}, Thrift::TTransportException::TIMED_OUT); } @@ -225,7 +227,7 @@ sub write if (!defined $sent || $sent == 0 ) { - die new Thrift::TTransportException(ref($self).': Could not write '.length($buf).' bytes '. + die Thrift::TTransportException->new(ref($self).': Could not write '.length($buf).' bytes '. $self->{host}.':'.$self->{host}, Thrift::TTransportException::END_OF_FILE); } @@ -314,7 +316,7 @@ sub __wait my @sockets = $self->{handle}->can_read( $self->{recvTimeout} / 1000 ); if (@sockets == 0) { - die new Thrift::TTransportException(ref($self).': timed out reading from '. + die Thrift::TTransportException->new(ref($self).': timed out reading from '. $self->{host}.':'.$self->{port}, Thrift::TTransportException::TIMED_OUT); } diff --git a/lib/perl/lib/Thrift/Transport.pm b/lib/perl/lib/Thrift/Transport.pm index 10c8ce2e57..41b7e150fe 100644 --- a/lib/perl/lib/Thrift/Transport.pm +++ b/lib/perl/lib/Thrift/Transport.pm @@ -54,7 +54,7 @@ use version 0.77; our $VERSION = version->declare("$Thrift::VERSION"); # sub isOpen { - die "abstract"; + die 'abstract'; } # @@ -64,7 +64,7 @@ sub isOpen # sub open { - die "abstract"; + die 'abstract'; } # @@ -72,7 +72,7 @@ sub open # sub close { - die "abstract"; + die 'abstract'; } # @@ -84,7 +84,7 @@ sub close # sub read { - die "abstract"; + die 'abstract'; } # @@ -116,7 +116,7 @@ sub readAll # sub write { - die "abstract"; + die 'abstract'; } # @@ -162,17 +162,17 @@ use version 0.77; our $VERSION = version->declare("$Thrift::VERSION"); sub listen { - die "abstract"; + die 'abstract'; } sub accept { - die "abstract"; + die 'abstract'; } sub close { - die "abstract"; + die 'abstract'; } diff --git a/lib/perl/lib/Thrift/UnixServerSocket.pm b/lib/perl/lib/Thrift/UnixServerSocket.pm index 7b857ce1e7..875e8049a7 100644 --- a/lib/perl/lib/Thrift/UnixServerSocket.pm +++ b/lib/perl/lib/Thrift/UnixServerSocket.pm @@ -37,8 +37,8 @@ use version 0.77; our $VERSION = version->declare("$Thrift::VERSION"); # If a single argument is given that is a hash: # @param[in] path unix domain socket file name # @param[in] queue the listen queue size (default is not specified is supplied by ServerSocket) -# @example my $serversock = new Thrift::UnixServerSocket($path); -# @example my $serversock = new Thrift::UnixServerSocket(path => "somepath", queue => 64); +# @example my $serversock = Thrift::UnixServerSocket->new($path); +# @example my $serversock = Thrift::UnixServerSocket->new(path => "somepath", queue => 64); # sub new { @@ -58,7 +58,7 @@ sub new sub __client { - return new Thrift::UnixSocket(); + return Thrift::UnixSocket->new(); } sub __listen @@ -75,7 +75,7 @@ sub __listen if ($self->{debug}) { $self->{debugHandler}->($error); } - die new Thrift::TTransportException($error, Thrift::TTransportException::NOT_OPEN); + die Thrift::TTransportException->new($error, Thrift::TTransportException::NOT_OPEN); }; return $sock; diff --git a/lib/perl/lib/Thrift/UnixSocket.pm b/lib/perl/lib/Thrift/UnixSocket.pm index 8b0045024f..ba386d1ce1 100644 --- a/lib/perl/lib/Thrift/UnixSocket.pm +++ b/lib/perl/lib/Thrift/UnixSocket.pm @@ -35,7 +35,7 @@ use version 0.77; our $VERSION = version->declare("$Thrift::VERSION"); # Takes a unix domain socket filename. # See Thrift::Socket for base class parameters. # @param[in] path path to unix socket file -# @example my $sock = new Thrift::UnixSocket($path); +# @example my $sock = Thrift::UnixSocket->new($path); # sub new { @@ -58,7 +58,7 @@ sub __open if ($self->{debug}) { $self->{debugHandler}->($error); } - die new Thrift::TTransportException($error, Thrift::TTransportException::NOT_OPEN); + die Thrift::TTransportException->new($error, Thrift::TTransportException::NOT_OPEN); }; return $sock; diff --git a/test/perl/TestClient.pl b/test/perl/TestClient.pl index 990274c5eb..96e3bec770 100755 --- a/test/perl/TestClient.pl +++ b/test/perl/TestClient.pl @@ -45,7 +45,7 @@ $|++; sub usage { - print <new($opts{'domain-socket'}); +} +elsif ($opts{ssl}) { + $socket = Thrift::SSLSocket->new(\%opts); +} +else { + $socket = Thrift::Socket->new($opts{host}, $opts{port}); } my $transport; if ($opts{transport} eq 'buffered') { - $transport = new Thrift::BufferedTransport($socket, 1024, 1024); -} elsif ($opts{transport} eq 'framed') { - $transport = new Thrift::FramedTransport($socket); -} else { + $transport = Thrift::BufferedTransport->new($socket, 1024, 1024); +} +elsif ($opts{transport} eq 'framed') { + $transport = Thrift::FramedTransport->new($socket); +} +else { usage(); exit 1; } @@ -112,20 +116,21 @@ sub usage { my $protocol; my $protocol2; if ($opts{protocol} eq 'binary' || $opts{protocol} eq 'multi') { - $protocol = new Thrift::BinaryProtocol($transport); -} else { + $protocol = Thrift::BinaryProtocol->new($transport); +} +else { usage(); exit 1; } my $secondService = undef; if (index($opts{protocol}, 'multi') == 0) { - $protocol2 = new Thrift::MultiplexedProtocol($protocol, "SecondService"); - $protocol = new Thrift::MultiplexedProtocol($protocol, "ThriftTest"); - $secondService = new ThriftTest::SecondServiceClient($protocol2); + $protocol2 = Thrift::MultiplexedProtocol->new($protocol, 'SecondService'); + $protocol = Thrift::MultiplexedProtocol->new($protocol, 'ThriftTest'); + $secondService = ThriftTest::SecondServiceClient->new($protocol2); } -my $testClient = new ThriftTest::ThriftTestClient($protocol); +my $testClient = ThriftTest::ThriftTestClient->new($protocol); eval { $transport->open(); @@ -146,52 +151,52 @@ sub usage { # # VOID TEST # -print("testVoid()"); +print('testVoid()'); $testClient->testVoid(); print(" = void\n"); # # STRING TEST # -print("testString(\"Test\")"); -my $s = $testClient->testString("Test"); -print(" = \"$s\"\n"); +print('testString("Test")'); +my $s = $testClient->testString('Test'); +print(qq| = "$s"\n|); exit(ERR_BASETYPES) if ($s ne 'Test'); # # MULTIPLEXED TEST # if (index($opts{protocol}, 'multi') == 0) { - print("secondtestString(\"Test2\")"); - $s = $secondService->secondtestString("Test2"); - print(" = \"$s\"\n"); + print('secondtestString("Test2")'); + $s = $secondService->secondtestString('Test2'); + print(qq| = "$s"\n|); exit(ERR_PROTOCOL) if ($s ne 'testString("Test2")'); } # # BOOL TEST # -print("testBool(1)"); +print('testBool(1)'); my $t = $testClient->testBool(1); print(" = $t\n"); exit(ERR_BASETYPES) if ($t ne 1); -print("testBool(0)"); +print('testBool(0)'); my $f = $testClient->testBool(0); print(" = $f\n"); -exit(ERR_BASETYPES) if ($f ne ""); +exit(ERR_BASETYPES) if ($f ne q||); # # BYTE TEST # -print("testByte(1)"); +print('testByte(1)'); my $u8 = $testClient->testByte(1); print(" = $u8\n"); # # I32 TEST # -print("testI32(-1)"); +print('testI32(-1)'); my $i32 = $testClient->testI32(-1); print(" = $i32\n"); exit(ERR_BASETYPES) if ($i32 ne -1); @@ -199,7 +204,7 @@ sub usage { # # I64 TEST # -print("testI64(-34359738368)"); +print('testI64(-34359738368)'); my $i64 = $testClient->testI64(-34359738368); print(" = $i64\n"); exit(ERR_BASETYPES) if ($i64 ne -34359738368); @@ -207,7 +212,7 @@ sub usage { # # DOUBLE TEST # -print("testDouble(-852.234234234)"); +print('testDouble(-852.234234234)'); my $dub = $testClient->testDouble(-852.234234234); print(" = $dub\n"); exit(ERR_BASETYPES) if ($dub ne -852.234234234); @@ -220,33 +225,33 @@ sub usage { # # STRUCT TEST # -print("testStruct({\"Zero\", 1, -3, -5})"); -my $out = new ThriftTest::Xtruct(); -$out->string_thing("Zero"); +print('testStruct({"Zero", 1, -3, -5})'); +my $out = ThriftTest::Xtruct->new(); +$out->string_thing('Zero'); $out->byte_thing(1); $out->i32_thing(-3); $out->i64_thing(-5); my $in = $testClient->testStruct($out); -print(" = {\"".$in->string_thing."\", ". - $in->byte_thing.", ". - $in->i32_thing.", ". +print(' = {"'.$in->string_thing.'", '. + $in->byte_thing.', '. + $in->i32_thing.', '. $in->i64_thing."}\n"); # # NESTED STRUCT TEST # -print("testNest({1, {\"Zero\", 1, -3, -5}, 5}"); -my $out2 = new ThriftTest::Xtruct2(); +print('testNest({1, {"Zero", 1, -3, -5}, 5}'); +my $out2 = ThriftTest::Xtruct2->new(); $out2->byte_thing(1); $out2->struct_thing($out); $out2->i32_thing(5); my $in2 = $testClient->testNest($out2); $in = $in2->struct_thing; -print(" = {".$in2->byte_thing.", {\"". - $in->string_thing."\", ". - $in->byte_thing.", ". - $in->i32_thing.", ". - $in->i64_thing."}, ". +print(' = {'.$in2->byte_thing.', {"'. + $in->string_thing.'", '. + $in->byte_thing.', '. + $in->i32_thing.', '. + $in->i64_thing.'}, '. $in2->i32_thing."}\n"); # @@ -256,28 +261,30 @@ sub usage { for (my $i = 0; $i < 5; ++$i) { $mapout->{$i} = $i-10; } -print("testMap({"); +print('testMap({'); my $first = 1; while( my($key,$val) = each %$mapout) { if ($first) { $first = 0; - } else { - print(", "); + } + else { + print(', '); } print("$key => $val"); } -print("})"); +print('})'); my $mapin = $testClient->testMap($mapout); -print(" = {"); +print(' = {'); $first = 1; while( my($key,$val) = each %$mapin){ if ($first) { $first = 0; - } else { - print(", "); + } + else { + print(', '); } print("$key => $val"); } @@ -291,11 +298,11 @@ sub usage { push(@$setout, $i); } -print("testSet({".join(",",@$setout)."})"); +print('testSet({'.join(',',@$setout).'})'); my $setin = $testClient->testSet($setout); -print(" = {".join(",",@$setout)."}\n"); +print(' = {'.join(',',@$setout)."}\n"); # # LIST TEST @@ -305,111 +312,111 @@ sub usage { push(@$listout, $i); } -print("testList({".join(",",@$listout)."})"); +print('testList({'.join(',',@$listout).'})'); my $listin = $testClient->testList($listout); -print(" = {".join(",",@$listin)."}\n"); +print(' = {'.join(',',@$listin)."}\n"); # # ENUM TEST # -print("testEnum(ONE)"); +print('testEnum(ONE)'); my $ret = $testClient->testEnum(ThriftTest::Numberz::ONE); print(" = $ret\n"); -print("testEnum(TWO)"); +print('testEnum(TWO)'); $ret = $testClient->testEnum(ThriftTest::Numberz::TWO); print(" = $ret\n"); -print("testEnum(THREE)"); +print('testEnum(THREE)'); $ret = $testClient->testEnum(ThriftTest::Numberz::THREE); print(" = $ret\n"); -print("testEnum(FIVE)"); +print('testEnum(FIVE)'); $ret = $testClient->testEnum(ThriftTest::Numberz::FIVE); print(" = $ret\n"); -print("testEnum(EIGHT)"); +print('testEnum(EIGHT)'); $ret = $testClient->testEnum(ThriftTest::Numberz::EIGHT); print(" = $ret\n"); # # TYPEDEF TEST # -print("testTypedef(309858235082523)"); +print('testTypedef(309858235082523)'); my $uid = $testClient->testTypedef(309858235082523); print(" = $uid\n"); # # NESTED MAP TEST # -print("testMapMap(1)"); +print('testMapMap(1)'); my $mm = $testClient->testMapMap(1); -print(" = {"); +print(' = {'); while( my ($key,$val) = each %$mm) { print("$key => {"); while( my($k2,$v2) = each %$val) { print("$k2 => $v2, "); } - print("}, "); + print('}, '); } print("}\n"); # # INSANITY TEST # -my $insane = new ThriftTest::Insanity(); +my $insane = ThriftTest::Insanity->new(); $insane->{userMap}->{ThriftTest::Numberz::FIVE} = 5000; -my $truck = new ThriftTest::Xtruct(); -$truck->string_thing("Hello2"); +my $truck = ThriftTest::Xtruct->new(); +$truck->string_thing('Hello2'); $truck->byte_thing(2); $truck->i32_thing(2); $truck->i64_thing(2); -my $truck2 = new ThriftTest::Xtruct(); -$truck2->string_thing("Goodbye4"); +my $truck2 = ThriftTest::Xtruct->new(); +$truck2->string_thing('Goodbye4'); $truck2->byte_thing(4); $truck2->i32_thing(4); $truck2->i64_thing(4); push(@{$insane->{xtructs}}, $truck); push(@{$insane->{xtructs}}, $truck2); -print("testInsanity()"); +print('testInsanity()'); my $whoa = $testClient->testInsanity($insane); -print(" = {"); +print(' = {'); while( my ($key,$val) = each %$whoa) { print("$key => {"); while( my($k2,$v2) = each %$val) { print("$k2 => {"); my $userMap = $v2->{userMap}; - print("{"); - if (ref($userMap) eq "HASH") { + print('{'); + if (ref($userMap) eq 'HASH') { while( my($k3,$v3) = each %$userMap) { print("$k3 => $v3, "); } } - print("}, "); + print('}, '); my $xtructs = $v2->{xtructs}; - print("{"); - if (ref($xtructs) eq "ARRAY") { + print('{'); + if (ref($xtructs) eq 'ARRAY') { foreach my $x (@$xtructs) { - print("{\"".$x->{string_thing}."\", ". - $x->{byte_thing}.", ".$x->{i32_thing}.", ".$x->{i64_thing}."}, "); + print('{"'.$x->{string_thing}.'", '. + $x->{byte_thing}.', '.$x->{i32_thing}.', '.$x->{i64_thing}.'}, '); } } - print("}"); + print('}'); - print("}, "); + print('}, '); } - print("}, "); + print('}, '); } print("}\n"); # # EXCEPTION TEST # -print("testException('Xception')"); +print(q|testException('Xception')|); eval { $testClient->testException('Xception'); print(" void\nFAILURE\n"); @@ -422,7 +429,7 @@ sub usage { # Normal tests done. # my $stop = gettimeofday(); -my $elp = sprintf("%d",1000*($stop - $start), 0); +my $elp = sprintf('%d',1000*($stop - $start), 0); print("Total time: $elp ms\n"); # diff --git a/test/perl/TestServer.pl b/test/perl/TestServer.pl index e8c1cfa9e3..d2b9a38ab3 100644 --- a/test/perl/TestServer.pl +++ b/test/perl/TestServer.pl @@ -27,7 +27,7 @@ use Time::HiRes qw(gettimeofday); $SIG{INT} = \&sigint_handler; - + use lib '../../lib/perl/lib'; use lib 'gen-perl'; @@ -48,7 +48,7 @@ $|++; sub usage { - print <new(); +my $handler2 = SecondServiceHandler->new(); +my $processor = ThriftTest::ThriftTestProcessor->new($handler); +my $processor2 = ThriftTest::SecondServiceProcessor->new($handler2); + my $serversocket; -if ($opts{"domain-socket"}) { - unlink($opts{"domain-socket"}); - $serversocket = new Thrift::UnixServerSocket($opts{"domain-socket"}); -} elsif ($opts{ssl}) { - $serversocket = new Thrift::SSLServerSocket(\%opts); -} else { - $serversocket = new Thrift::ServerSocket(\%opts); +if ($opts{'domain-socket'}) { + unlink($opts{'domain-socket'}); + $serversocket = Thrift::UnixServerSocket->new($opts{'domain-socket'}); +} +elsif ($opts{ssl}) { + $serversocket = Thrift::SSLServerSocket->new(\%opts); +} +else { + $serversocket = Thrift::ServerSocket->new(\%opts); } my $transport; if ($opts{transport} eq 'buffered') { - $transport = new Thrift::BufferedTransportFactory(); -} elsif ($opts{transport} eq 'framed') { - $transport = new Thrift::FramedTransportFactory(); -} else { + $transport = Thrift::BufferedTransportFactory->new(); +} +elsif ($opts{transport} eq 'framed') { + $transport = Thrift::FramedTransportFactory->new(); +} +else { usage(); exit 1; } my $protocol; if ($opts{protocol} eq 'binary' || $opts{protocol} eq 'multi') { - $protocol = new Thrift::BinaryProtocolFactory(); -} else { + $protocol = Thrift::BinaryProtocolFactory->new(); +} +else { usage(); exit 1; } if (index($opts{protocol}, 'multi') == 0) { - my $newProcessor = new Thrift::MultiplexedProcessor($protocol); + my $newProcessor = Thrift::MultiplexedProcessor->new($protocol); $newProcessor->defaultProcessor($processor); - $newProcessor->registerProcessor("ThriftTest", $processor); - $newProcessor->registerProcessor("SecondService", $processor2); + $newProcessor->registerProcessor('ThriftTest', $processor); + $newProcessor->registerProcessor('SecondService', $processor2); $processor = $newProcessor; } my $ssltag = ''; if ($opts{ssl}) { - $ssltag = "(SSL)"; + $ssltag = '(SSL)'; } my $listening_on = "$opts{port} $ssltag"; -if ($opts{"domain-socket"}) { - $listening_on = $opts{"domain-socket"}; +if ($opts{'domain-socket'}) { + $listening_on = $opts{'domain-socket'}; } -my $server = new Thrift::SimpleServer($processor, $serversocket, $transport, $protocol); -print "Starting \"simple\" server ($opts{transport}/$opts{protocol}) listen on: $listening_on\n"; +my $server = Thrift::SimpleServer->new($processor, $serversocket, $transport, $protocol); +print qq|Starting "simple" server ($opts{transport}/$opts{protocol}) listen on: $listening_on\n|; $server->serve(); print "done.\n"; @@ -169,70 +175,67 @@ sub new { return bless($self, $classname); } -sub testVoid() { +sub testVoid { print("testVoid()\n"); } -sub testString() { +sub testString { my $self = shift; my $thing = shift; print("testString($thing)\n"); return $thing; } -sub testBool() { +sub testBool { my $self = shift; my $thing = shift; - my $str = $thing ? "true" : "false"; + my $str = $thing ? 'true' : 'false'; print("testBool($str)\n"); return $thing; } -sub testByte() { +sub testByte { my $self = shift; my $thing = shift; print("testByte($thing)\n"); return $thing; } -sub testI32() { +sub testI32 { my $self = shift; my $thing = shift; print("testI32($thing)\n"); return $thing; } -sub testI64() { +sub testI64 { my $self = shift; my $thing = shift; print("testI64($thing)\n"); return $thing; } -sub testDouble() { +sub testDouble { my $self = shift; my $thing = shift; print("testDouble($thing)\n"); return $thing; } -sub testBinary() { +sub testBinary { my $self = shift; my $thing = shift; my @bytes = split //, $thing; - print("testBinary("); - foreach (@bytes) - { - printf "%02lx", ord $_; - } - print(")\n"); + print 'testBinary('; + printf( '%02lx', ord $_ ) foreach (@bytes); + print ")\n"; return $thing; } -sub testStruct() { +sub testStruct { my $self = shift; my $thing = shift; - printf("testStruct({\"%s\", %d, %d, %lld})\n", + printf(qq|testStruct({"%s", %d, %d, %lld})\n|, $thing->{string_thing}, $thing->{byte_thing}, $thing->{i32_thing}, @@ -240,11 +243,11 @@ () return $thing; } -sub testNest() { +sub testNest { my $self = shift; my $nest = shift; my $thing = $nest->{struct_thing}; - printf("testNest({%d, {\"%s\", %d, %d, %lld}, %d})\n", + printf(qq|testNest({%d, {"%s", %d, %d, %lld}, %d})\n|, $nest->{byte_thing}, $thing->{string_thing}, $thing->{byte_thing}, @@ -254,92 +257,58 @@ () return $nest; } -sub testMap() { +sub testMap { my $self = shift; my $thing = shift; - print("testMap({"); - my $first = 1; - foreach my $key (keys %$thing) { - if ($first) { - $first = 0; - } else { - print(", "); - } - print("$key => $thing->{$key}"); - } - print("})\n"); + printf "testMap({%s})\n", + join( ', ', + map { $_ . ' => ' . $thing->{$_} } + sort keys %$thing + ); return $thing; } -sub testStringMap() { +sub testStringMap { my $self = shift; my $thing = shift; - print("testStringMap({"); - my $first = 1; - foreach my $key (keys %$thing) { - if ($first) { - $first = 0; - } else { - print(", "); - } - print("$key => $thing->{$key}"); - } - print("})\n"); + printf "testStringMap({%s})\n", + join( ', ', + map { $_ . ' => ' . $thing->{$_} } + sort keys %$thing + ); return $thing; } -sub testSet() { +sub testSet { my $self = shift; my $thing = shift; - my @arr; - my $result = \@arr; - print("testSet({"); - my $first = 1; - foreach my $key (keys %$thing) { - if ($first) { - $first = 0; - } else { - print(", "); - } - print("$key"); - push(@arr, $key); - } - print("})\n"); - return $result; + my @result = sort keys %$thing; + printf "testSet({%s})\n", join(', ', @result ); + return \@result; } -sub testList() { +sub testList { my $self = shift; my $thing = shift; - print("testList({"); - my $first = 1; - foreach my $key (@$thing) { - if ($first) { - $first = 0; - } else { - print(", "); - } - print("$key"); - } - print("})\n"); + print "testList({%s})\n", join(', ', @$thing); return $thing; } -sub testEnum() { +sub testEnum { my $self = shift; my $thing = shift; - print("testEnum($thing)\n"); + print "testEnum($thing)\n"; return $thing; } -sub testTypedef() { +sub testTypedef { my $self = shift; my $thing = shift; print("testTypedef($thing)\n"); return $thing; } -sub testMapMap() { +sub testMapMap { my $self = shift; my $hello = shift; @@ -348,25 +317,25 @@ () return $result; } -sub testInsanity() { +sub testInsanity { my $self = shift; my $argument = shift; print("testInsanity()\n"); - my $hello = new ThriftTest::Xtruct({string_thing => "Hello2", byte_thing => 2, i32_thing => 2, i64_thing => 2}); + my $hello = ThriftTest::Xtruct->new({string_thing => 'Hello2', byte_thing => 2, i32_thing => 2, i64_thing => 2}); my @hellos; push(@hellos, $hello); - my $goodbye = new ThriftTest::Xtruct({string_thing => "Goodbye4", byte_thing => 4, i32_thing => 4, i64_thing => 4}); + my $goodbye = ThriftTest::Xtruct->new({string_thing => 'Goodbye4', byte_thing => 4, i32_thing => 4, i64_thing => 4}); my @goodbyes; push(@goodbyes, $goodbye); - my $crazy = new ThriftTest::Insanity({userMap => { ThriftTest::Numberz::EIGHT => 8 }, xtructs => \@goodbyes}); - my $loony = new ThriftTest::Insanity(); + my $crazy = ThriftTest::Insanity->new({userMap => { ThriftTest::Numberz::EIGHT => 8 }, xtructs => \@goodbyes}); + my $loony = ThriftTest::Insanity->new(); my $result = { 1 => { ThriftTest::Numberz::TWO => $argument, ThriftTest::Numberz::THREE => $argument }, 2 => { ThriftTest::Numberz::SIX => $loony } }; return $result; } -sub testMulti() { +sub testMulti { my $self = shift; my $arg0 = shift; my $arg1 = shift; @@ -376,39 +345,43 @@ () my $arg5 = shift; print("testMulti()\n"); - return new ThriftTest::Xtruct({string_thing => "Hello2", byte_thing => $arg0, i32_thing => $arg1, i64_thing => $arg2}); + return ThriftTest::Xtruct->new({string_thing => 'Hello2', byte_thing => $arg0, i32_thing => $arg1, i64_thing => $arg2}); } -sub testException() { +sub testException { my $self = shift; my $arg = shift; print("testException($arg)\n"); - if ($arg eq "Xception") { - die new ThriftTest::Xception({errorCode => 1001, message => $arg}); - } elsif ($arg eq "TException") { - die "astring"; # all unhandled exceptions become TExceptions - } else { - return new ThriftTest::Xtruct({string_thing => $arg}); + if ($arg eq 'Xception') { + die ThriftTest::Xception->new({errorCode => 1001, message => $arg}); + } + elsif ($arg eq 'TException') { + die 'astring'; # all unhandled exceptions become TExceptions + } + else { + return ThriftTest::Xtruct->new({string_thing => $arg}); } } -sub testMultiException() { +sub testMultiException { my $self = shift; my $arg0 = shift; my $arg1 = shift; printf("testMultiException(%s, %s)\n", $arg0, $arg1); - if ($arg0 eq "Xception") { - die new ThriftTest::Xception({errorCode => 1001, message => "This is an Xception"}); - } elsif ($arg0 eq "Xception2") { - my $struct_thing = new ThriftTest::Xtruct({string_thing => "This is an Xception2"}); - die new ThriftTest::Xception2({errorCode => 2002, struct_thing => $struct_thing}); - } else { - return new ThriftTest::Xtruct({string_thing => $arg1}); + if ($arg0 eq 'Xception') { + die ThriftTest::Xception->new({errorCode => 1001, message => 'This is an Xception'}); + } + elsif ($arg0 eq 'Xception2') { + my $struct_thing = ThriftTest::Xtruct->new({string_thing => 'This is an Xception2'}); + die ThriftTest::Xception2->new({errorCode => 2002, struct_thing => $struct_thing}); + } + else { + return ThriftTest::Xtruct->new({string_thing => $arg1}); } } -sub testOneway() { +sub testOneway { my $self = shift; my $num = shift; print("testOneway($num): received\n"); @@ -428,11 +401,11 @@ sub new { return bless($self, $classname); } -sub secondtestString() { +sub secondtestString { my $self = shift; my $thing = shift; print("testString($thing)\n"); - return "testString(\"" . $thing . "\")"; + return qq|testString("$thing")|; } 1; diff --git a/tutorial/perl/PerlClient.pl b/tutorial/perl/PerlClient.pl index 1d596568df..7c23289ce5 100644 --- a/tutorial/perl/PerlClient.pl +++ b/tutorial/perl/PerlClient.pl @@ -37,10 +37,10 @@ use Data::Dumper; -my $socket = new Thrift::Socket('localhost',9090); -my $transport = new Thrift::BufferedTransport($socket,1024,1024); -my $protocol = new Thrift::BinaryProtocol($transport); -my $client = new tutorial::CalculatorClient($protocol); +my $socket = Thrift::Socket->new('localhost',9090); +my $transport = Thrift::BufferedTransport->new($socket,1024,1024); +my $protocol = Thrift::BinaryProtocol->new($transport); +my $client = tutorial::CalculatorClient->new($protocol); eval{ @@ -53,7 +53,7 @@ my $sum = $client->add(1,1); print "1+1=$sum\n"; - my $work = new tutorial::Work(); + my $work = tutorial::Work->new(); $work->op(tutorial::Operation::DIVIDE); $work->num1(1); @@ -63,7 +63,7 @@ $client->calculate(1, $work); print "Whoa! We can divide by zero?\n"; }; if($@) { - warn "InvalidOperation: ".Dumper($@); + warn 'InvalidOperation: '.Dumper($@); } $work->op(tutorial::Operation::SUBTRACT); diff --git a/tutorial/perl/PerlServer.pl b/tutorial/perl/PerlServer.pl index adec97863c..dfe6b89a15 100644 --- a/tutorial/perl/PerlServer.pl +++ b/tutorial/perl/PerlServer.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # # Licensed to the Apache Software Foundation (ASF) under one @@ -67,20 +67,20 @@ sub calculate } elsif ($op == tutorial::Operation::DIVIDE) { if ($num2 == 0) { - my $x = new tutorial::InvalidOperation; + my $x = tutorial::InvalidOperation->new(); $x->whatOp($op); $x->why('Cannot divide by 0'); die $x; } $val = $num1 / $num2; } else { - my $x = new tutorial::InvalidOperation; + my $x = tutorial::InvalidOperation->new(); $x->whatOp($op); $x->why('Invalid operation'); die $x; } - my $log = new shared::SharedStruct; + my $log = shared::SharedStruct->new(); $log->key($logid); $log->value(int($val)); $self->{log}->{$logid} = $log; @@ -104,10 +104,10 @@ sub zip eval { - my $handler = new CalculatorHandler; - my $processor = new tutorial::CalculatorProcessor($handler); - my $serversocket = new Thrift::ServerSocket(9090); - my $forkingserver = new Thrift::ForkingServer($processor, $serversocket); + my $handler = CalculatorHandler->new(); + my $processor = tutorial::CalculatorProcessor->new($handler); + my $serversocket = Thrift::ServerSocket->new(9090); + my $forkingserver = Thrift::ForkingServer->new($processor, $serversocket); print "Starting the server...\n"; $forkingserver->serve(); print "done.\n"; ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org > Replace the use of Perl Indirect Object Syntax calls to new() > -------------------------------------------------------------- > > Key: THRIFT-4382 > URL: https://issues.apache.org/jira/browse/THRIFT-4382 > Project: Thrift > Issue Type: Improvement > Components: Perl - Compiler > Reporter: Dean Hamstead > Assignee: James E. King III > Priority: Minor > > Using Indirect Object Syntax to instantiate objects is not recommended as per https://perldoc.perl.org/perlobj.html#Invoking-Class-Methods -- This message was sent by Atlassian JIRA (v7.6.3#76005)