Skip to content

Commit

Permalink
Clarified defined logic, param checking, and strings
Browse files Browse the repository at this point in the history
This commit clarifies the defined logic within the codebase to use
defined where needed, and remove where not correct.  Additionally
added more specific param checking on methods to ensure we're not
validating params we're not expecting.  Also updated to single
quotes where interpolation isn't required.
  • Loading branch information
renderorange committed Jul 16, 2024
1 parent 51b6ba3 commit e106776
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/Pasteburn/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ C<Pasteburn::Config> loads the project config.
Load the config and return a C<Pasteburn::Config> object.
Required keys and values are validated during load, and exception thrown if not defined or containing the default values.
Required keys and values are validated during load, and exception thrown if key does not exist and doesn't match the expected values.
=back
Expand Down
2 changes: 1 addition & 1 deletion lib/Pasteburn/Crypt/Hash.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ sub validate {
@_,
};

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

Expand Down
4 changes: 2 additions & 2 deletions lib/Pasteburn/Crypt/Storage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sub encode {
@_,
};

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

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

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

Expand Down
20 changes: 10 additions & 10 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} ) {
if ( !defined $arg->{$key} ) {
if ( !$arg->{$key} ) {
next;
}

Expand Down Expand Up @@ -117,7 +117,7 @@ sub store {
@_,
};

foreach my $attribute ( 'passphrase', 'secret' ) {
foreach my $attribute (qw{passphrase secret}) {
if ( !defined $self->{$attribute} ) {
die "$attribute is required";
}
Expand Down Expand Up @@ -208,11 +208,11 @@ sub validate_passphrase {
};

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

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

if ( !defined $arg->{passphrase} ) {
Expand All @@ -225,7 +225,7 @@ sub validate_passphrase {
# but not allow an undef to be stored.
# although unlikely to fail, still verify the hashed passphrase is in the object.
if ( !defined $self->passphrase ) {
die "passphrase is not set";
die 'passphrase is not set';
}

my $crypt = Pasteburn::Crypt::Hash->new();
Expand All @@ -241,15 +241,15 @@ sub decode_secret {
};

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

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

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

my $crypt_storage = Pasteburn::Crypt::Storage->new( passphrase => $arg->{passphrase} );
Expand All @@ -268,11 +268,11 @@ sub delete_secret {
my $self = shift;

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

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

my $sql = q{
Expand Down
4 changes: 2 additions & 2 deletions t/lib/Pasteburn/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ sub create_test_app {
@_,
);

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

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

override(
Expand Down

0 comments on commit e106776

Please sign in to comment.