Skip to content

Commit

Permalink
Reverse unless in codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
renderorange committed Jul 11, 2024
1 parent ab55526 commit 51b6ba3
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 48 deletions.
2 changes: 1 addition & 1 deletion bin/delete_expired_secrets.pl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
die "select secrets failed: $exception";
};

exit unless @secrets;
exit if !@secrets;

my @bind_values;
foreach my $secret_hashref (@secrets) {
Expand Down
2 changes: 1 addition & 1 deletion bin/increment_version.pl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ sub find_all_files {
File::Find::find(
sub {
my $file = $File::Find::name;
return unless $file =~ /\.pm$/;
return if $file !~ /\.pm$/;

push( @modules, File::Spec->abs2rel( $file, $dir ) );
},
Expand Down
4 changes: 2 additions & 2 deletions lib/Pasteburn.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ BEGIN {
set views => config->{appdir} . 'views';
set footer => $conf->{footer};

unless ( config->{views} ) {
if ( !config->{views} ) {
die("FATAL: views is not set");
}
}
Expand All @@ -34,7 +34,7 @@ hook before => sub {

foreach my $session_id ( keys %{$session_secrets} ) {
my $secret_obj = Pasteburn::Model::Secrets->get( id => $session_id );
unless ($secret_obj) {
if ( !$secret_obj ) {
delete $session_secrets->{$session_id};
}
}
Expand Down
15 changes: 7 additions & 8 deletions lib/Pasteburn/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sub _get_conf_path {
sub _load {
my $rc = _get_conf_path();

unless ( -f $rc ) {
if ( !-f $rc ) {
die "$rc is not present";
}

Expand All @@ -46,29 +46,28 @@ sub _validate {

# verify required config sections
foreach my $required (qw{ secret passphrase cookie footer }) {
unless ( exists $config->{$required} ) {
if ( !exists $config->{$required} ) {
die "config section $required is required\n";
}
}

unless ( exists $config->{secret}{age} ) {
if ( !exists $config->{secret}{age} ) {
die "config section secret age is required\n";
}

if ( $config->{secret}{age} < 1 ) {
die "config section secret age must be a positive integer\n";
}

unless ( exists $config->{secret}{scrub} && ( $config->{secret}{scrub} == 1 || $config->{secret}{scrub} == 0 ) ) {
if ( !exists $config->{secret}{scrub} || $config->{secret}{scrub} !~ qr/^[0|1]$/ ) {
die "config section secret scrub is required\n";
}

unless ( exists $config->{passphrase}{allow_blank}
&& ( $config->{passphrase}{allow_blank} == 1 || $config->{passphrase}{allow_blank} == 0 ) ) {
if ( !exists $config->{passphrase}{allow_blank} || $config->{passphrase}{allow_blank} !~ qr/^[0|1]$/ ) {
die "config section passphrase allow_blank is required\n";
}

unless ( exists $config->{cookie}{secret_key} && $config->{cookie}{secret_key} ) {
if ( !exists $config->{cookie}{secret_key} || !$config->{cookie}{secret_key} ) {
die "config section cookie secret_key is required\n";
}

Expand All @@ -77,7 +76,7 @@ sub _validate {
die "config section cookie secret_key is the default string and must be updated\n";
}

unless ( exists $config->{footer}{links} && ( $config->{footer}{links} == 1 || $config->{footer}{links} == 0 ) ) {
if ( !exists $config->{footer}{links} || $config->{footer}{links} !~ qr/^[0|1]$/ ) {
die "config section footer links is required\n";
}

Expand Down
10 changes: 5 additions & 5 deletions lib/Pasteburn/Controller/Secret.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ post q{/secret} => sub {
};

if ( config->{passphrase}{allow_blank} ) {
unless ($secret) {
if ( !$secret ) {
$template_params->{message_type} = 'error';
$template_params->{message} = 'The secret parameter is required';
response->{status} = HTTP::Status::HTTP_BAD_REQUEST;
return template secret => $template_params;
}
}
else {
unless ( $secret && $passphrase ) {
if ( !$secret || !$passphrase ) {
$template_params->{message_type} = 'error';
$template_params->{message} = 'The secret and passphrase parameters are required';
response->{status} = HTTP::Status::HTTP_BAD_REQUEST;
Expand Down Expand Up @@ -86,7 +86,7 @@ get q{/secret/:id} => sub {

# check the db for the secret.
my $secret_obj = Pasteburn::Model::Secrets->get( id => $id );
unless ($secret_obj) {
if ( !$secret_obj ) {
my $session_secrets = session->read('secrets');
if ( exists $session_secrets->{$id} ) {
delete $session_secrets->{$id};
Expand Down Expand Up @@ -134,7 +134,7 @@ post q{/secret/:id} => sub {

# check the db for the secret.
my $secret_obj = Pasteburn::Model::Secrets->get( id => $id );
unless ($secret_obj) {
if ( !$secret_obj ) {
Pasteburn::set_session_response(
{ type => 'error',
message => 'That secret does not exist or has expired',
Expand Down Expand Up @@ -177,7 +177,7 @@ post q{/secret/:id} => sub {
return template secret => $template_params;
}

unless ( $secret_obj->validate_passphrase( passphrase => $passphrase ) ) {
if ( !$secret_obj->validate_passphrase( passphrase => $passphrase ) ) {
$template_params->{message_type} = 'error';
$template_params->{message} = 'That passphrase is not correct';
response->{status} = HTTP::Status::HTTP_UNAUTHORIZED;
Expand Down
8 changes: 4 additions & 4 deletions lib/Pasteburn/Crypt/Hash.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sub generate {
@_,
};

unless ( defined $arg->{string} ) {
if ( !defined $arg->{string} ) {
die "string is required\n";
}

Expand Down Expand Up @@ -63,11 +63,11 @@ sub validate {
@_,
};

unless ( $arg->{hash} ) {
if ( !$arg->{hash} ) {
die "hash is required\n";
}

unless ( defined $arg->{string} ) {
if ( !defined $arg->{string} ) {
die "string is required\n";
}

Expand All @@ -76,7 +76,7 @@ sub validate {

my $input = $self->generate( string => $arg->{string}, salt => $salt );

return unless length($input) == length( $arg->{hash} );
return if length($input) != length( $arg->{hash} );

my $match = 1;
foreach my $i ( 0 .. length($input) - 1 ) {
Expand Down
6 changes: 3 additions & 3 deletions lib/Pasteburn/Crypt/Storage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sub new {
@_,
};

unless ( defined $arg->{passphrase} ) {
if ( !defined $arg->{passphrase} ) {
die "passphrase argument is required\n";
}

Expand All @@ -30,7 +30,7 @@ sub encode {
@_,
};

unless ( $arg->{secret} ) {
if ( !$arg->{secret} ) {
die "secret argument is required\n";
}

Expand All @@ -44,7 +44,7 @@ sub decode {
@_,
};

unless ( $arg->{secret} ) {
if ( !$arg->{secret} ) {
die "secret argument is required\n";
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Pasteburn/DB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ sub load {
$module_path =~ s/\w+\.pm//;
my $db = Cwd::realpath( $module_path . '/../../db/pasteburn.sqlite3' );

unless ( -f $db ) {
if ( !-f $db ) {
die "$db is not readable";
}

Expand Down
28 changes: 14 additions & 14 deletions lib/Pasteburn/Model/Secrets.pm
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ sub get {
my ( @where, @bind_values );

foreach my $key ( keys %{$arg} ) {
unless ( defined $arg->{$key} ) {
if ( !defined $arg->{$key} ) {
next;
}

Expand All @@ -103,7 +103,7 @@ sub get {

my $secret_hashref = $class->_dbh->selectrow_hashref( $sql, undef, @bind_values );

unless ($secret_hashref) {
if ( !$secret_hashref ) {
return;
}

Expand All @@ -118,7 +118,7 @@ sub store {
};

foreach my $attribute ( 'passphrase', 'secret' ) {
unless ( defined $self->{$attribute} ) {
if ( !defined $self->{$attribute} ) {
die "$attribute is required";
}
}
Expand Down Expand Up @@ -169,7 +169,7 @@ sub store {
sub _generate_id {
my $self = shift;

unless ( Scalar::Util::blessed($self) ) {
if ( !Scalar::Util::blessed($self) ) {
die "_generate_id must be called as an object method";
}

Expand All @@ -179,7 +179,7 @@ sub _generate_id {
sub _update_object {
my $self = shift;

unless ( Scalar::Util::blessed($self) ) {
if ( !Scalar::Util::blessed($self) ) {
die "_update_object must be called as an object method";
}

Expand Down Expand Up @@ -207,15 +207,15 @@ sub validate_passphrase {
@_,
};

unless ( Scalar::Util::blessed($self) ) {
if ( !Scalar::Util::blessed($self) ) {
die "validate_passphrase must be called as an object method";
}

unless ( $self->id ) {
if ( !$self->id ) {
die "validate_passphrase cannot be run for a nonexistent secret";
}

unless ( defined $arg->{passphrase} ) {
if ( !defined $arg->{passphrase} ) {
die "passphrase is required";
}

Expand All @@ -224,7 +224,7 @@ sub validate_passphrase {
# the code up to this point will allow empty string submitted from the interface,
# but not allow an undef to be stored.
# although unlikely to fail, still verify the hashed passphrase is in the object.
unless ( defined $self->passphrase ) {
if ( !defined $self->passphrase ) {
die "passphrase is not set";
}

Expand All @@ -240,15 +240,15 @@ sub decode_secret {
@_,
};

unless ( Scalar::Util::blessed($self) ) {
if ( !Scalar::Util::blessed($self) ) {
die "decode_secret must be called as an object method";
}

unless ( $self->id ) {
if ( !$self->id ) {
die "decode_secret cannot be run for a nonexistent secret";
}

unless ( defined $arg->{passphrase} ) {
if ( !defined $arg->{passphrase} ) {
die "passphrase is required";
}

Expand All @@ -267,11 +267,11 @@ sub decode_secret {
sub delete_secret {
my $self = shift;

unless ( Scalar::Util::blessed($self) ) {
if ( !Scalar::Util::blessed($self) ) {
die "delete_secret must be called as an object method";
}

unless ( $self->id ) {
if ( !$self->id ) {
die "delete_secret cannot be run for a nonexistent secret";
}

Expand Down
2 changes: 1 addition & 1 deletion t/996_perl-tidy.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use warnings;
use FindBin;
use Test::More;

unless ( $ENV{TEST_AUTHOR} ) {
if ( !$ENV{TEST_AUTHOR} ) {
my $msg = 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.';
plan( skip_all => $msg );
}
Expand Down
2 changes: 1 addition & 1 deletion t/997_perl-critic.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use FindBin;
use File::Spec;
use Test::More;

unless ( $ENV{TEST_AUTHOR} ) {
if ( !$ENV{TEST_AUTHOR} ) {
my $msg = 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.';
plan( skip_all => $msg );
}
Expand Down
2 changes: 1 addition & 1 deletion t/998_pod-checker.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use warnings;
use FindBin;
use Test::More;

unless ( $ENV{TEST_AUTHOR} ) {
if ( !$ENV{TEST_AUTHOR} ) {
my $msg = 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.';
plan( skip_all => $msg );
}
Expand Down
10 changes: 5 additions & 5 deletions t/lib/Pasteburn/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sub import {

if ( $args{tests} ) {
$class->builder->plan( tests => $args{tests} )
unless $args{tests} eq 'no_declare';
if $args{tests} ne 'no_declare';
}
elsif ( $args{skip_all} ) {
$class->builder->plan( skip_all => $args{skip_all} );
Expand All @@ -34,7 +34,7 @@ sub import {
CLEANUP => 0,
);

unless ( $args{skip_db} ) {
if ( !$args{skip_db} ) {
init_db();
}

Expand Down Expand Up @@ -86,7 +86,7 @@ sub write_config {
%{$config_tiny} = %{$args{config}};

die( "unable to write config\n" )
unless $config_tiny->write( $rc );
if !$config_tiny->write( $rc );

return $rc;
}
Expand Down Expand Up @@ -150,12 +150,12 @@ sub create_test_app {
);

foreach my $required ( keys %args ) {
unless ( defined $args{$required} ) {
if ( !defined $args{$required} ) {
die "$required is required";
}
}

unless ( ref $args{config} eq 'HASH' ) {
if ( !ref $args{config} eq 'HASH' ) {
die "config must be a hashref";
}

Expand Down
2 changes: 1 addition & 1 deletion t/unit/lib-Pasteburn-Config/_validate.t
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ EXCEPTIONS: {
my $stored = delete $config_expected->{$required}{$required_sub_key};

dies_ok { Pasteburn::Config::_validate( $config_expected ) }
"dies if config is missing $required $required_sub_key key";
"dies if config is missing $required $required_sub_key";

$config_expected->{$required}{$required_sub_key} = $stored;
}
Expand Down

0 comments on commit 51b6ba3

Please sign in to comment.