Skip to content

Commit

Permalink
Fixed some percritic issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cmouse committed Feb 18, 2014
1 parent 1542f87 commit f7f27cf
Showing 1 changed file with 39 additions and 23 deletions.
62 changes: 39 additions & 23 deletions rev.pl
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ package RemoteBackendHandler;
my $sym = $syms[$_];
my $bin = sprintf('%05b', $_);

$char2bits[ ord lc $sym ] = $bin;
$char2bits[ ord uc $sym ] = $bin;
$char2bits[ ord(lc($sym)) ] = $bin;
$char2bits[ ord(uc($sym)) ] = $bin;

do {
$bits2char{$bin} = $sym;
} while $bin =~ s/(.+)0\z/$1/s;
}


sub encode_base32_pre58($) {
length($_[0]) == bytes::length($_[0])
sub encode_base32_pre58 {
my $data = shift;
length($data) == bytes::length($data)
or Carp::croak('Data contains non-bytes');

my $str = unpack('B*', $_[0]);
my $str = unpack('B*', $data);

if (length($str) < 8*1024) {
return join '', @bits2char{ $str =~ /.{1,5}/g };
Expand All @@ -55,11 +56,12 @@ ($)
}


sub encode_base32_perl58($) {
$_[0] =~ tr/\x00-\xFF//c
sub encode_base32_perl58 {
my $data = shift;
$data =~ tr/\x00-\xFF//c
and Carp::croak('Data contains non-bytes');

my $str = unpack('B*', $_[0]);
my $str = unpack('B*', $data);

if (length($str) < 8*1024) {
return join '', @bits2char{ unpack '(a5)*', $str };
Expand All @@ -71,16 +73,17 @@ ($)
}


sub decode_base32_pre58($) {
( length($_[0]) != bytes::length($_[0]) || $_[0] =~ tr/ybcdfghjklmnpqrstvwxz1234567890-//c )
sub decode_base32_pre58 {
my $data = shift;
( length($data) != bytes::length($data) || $data =~ tr/ybcdfghjklmnpqrstvwxz1234567890-//c )
and Carp::croak('Data contains non-base32 characters');

my $str;
if (length($_[0]) < 8*1024) {
$str = join '', @char2bits[ unpack 'C*', $_[0] ];
if (length($data) < 8*1024) {
$str = join '', @char2bits[ unpack 'C*', $data ];
} else {
# Slower, but uses less memory
($str = $_[0]) =~ s/(.)/$char2bits[ord($1)]/sg;
($str = $data) =~ s/(.)/$char2bits[ord($1)]/sg;
}

my $padding = length($str) % 8;
Expand All @@ -93,16 +96,17 @@ ($)
}


sub decode_base32_perl58($) {
$_[0] =~ tr/ybcdfghjklmnpqrstvwxz1234567890-//c
sub decode_base32_perl58 {
my $data = shift;
$data =~ tr/ybcdfghjklmnpqrstvwxz1234567890-//c
and Carp::croak('Data contains non-base32 characters');

my $str;
if (length($_[0]) < 8*1024) {
$str = join '', @char2bits[ unpack 'C*', $_[0] ];
if (length($data) < 8*1024) {
$str = join '', @char2bits[ unpack 'C*', $data ];
} else {
# Slower, but uses less memory
($str = $_[0]) =~ s/(.)/$char2bits[ord($1)]/sg;
($str = $data) =~ s/(.)/$char2bits[ord($1)]/sg;
}

my $padding = length($str) % 8;
Expand Down Expand Up @@ -183,20 +187,23 @@ sub run {
$self->{_result} = $self->{_j}->false;
$self->{_log} = [];
}
return;
}

## Add a line into log
sub log {
sub rlog {
my $self = shift;
push @{$self->{_log}}, shift;
return;
}

## Set return value to 'true', optionally log
sub success {
my $self = shift;
$self->{_result} = $self->{_j}->true;
my $l = shift;
$self->log($l) if ($l);
$self->rlog($l) if ($l);
return;
}

## Set result to result, optionally log
Expand All @@ -205,15 +212,17 @@ sub result {
my $res = shift;
$self->{_result} = $res;
my $l = shift;
$self->log($l) if ($l);
$self->rlog($l) if ($l);
return;
}

## Set result to 'false', optionally log
sub error {
my $self = shift;
$self->{_result} = $self->{_j}->false;
my $l = shift;
$self->log($l) if ($l);
$self->rlog($l) if ($l);
return;
}

## Add rr into result rr(name,type,content,prio,ttl)
Expand All @@ -240,6 +249,7 @@ sub rr {
'auth' => int($auth),
'domain_id' => int($d_id)
};
return;
}

## Return database connection
Expand Down Expand Up @@ -299,6 +309,7 @@ sub do_initialize {
my $d = DBI->connect_cached($self->{_dsn}, $self->{_username}, $self->{_password}) or die;

$self->success("Autoreverse backend initialized");
return;
}

## lookup method
Expand Down Expand Up @@ -419,7 +430,7 @@ sub do_lookup {
$revdom =~s/arpaip6//; # we need to remove this

# decode $tmp, if possible.
eval '$tmp = decode_base32($tmp);';
eval { $tmp = decode_base32($tmp); };
if ($@) {
$self->error($@);
return;
Expand Down Expand Up @@ -451,6 +462,7 @@ sub do_lookup {

$self->error;
}
return;
}


Expand All @@ -471,6 +483,7 @@ sub do_adddomainkey {

# get the inserted record ID and return it
$self->{_result} = int($kid);
return;
}

# getDomainKeys method call
Expand All @@ -494,6 +507,7 @@ sub do_getdomainkeys {

# no keys found?
$self->error unless (@{$self->{_result}});
return;
}

# setDomainMetaData method call
Expand All @@ -517,6 +531,7 @@ sub do_setdomainmetadata {

# it always succeeds
$self->success;
return;
}

# getDomainMetaData method call
Expand All @@ -539,6 +554,7 @@ sub do_getdomainmetadata {
}

$self->error unless (@{$self->{_result}});
return;
}

package main;
Expand Down

0 comments on commit f7f27cf

Please sign in to comment.