summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2007-08-30 17:52:49 +0000
committerRuss Allbery <rra@stanford.edu>2007-08-30 17:52:49 +0000
commit100779a7b7f71749b10fe078b8f38307319ef88f (patch)
treed17684239bca7f167ccf78785eb3d6289d84a59f
parent0ec04f853bd1a436b33ddad0feac10e61c791f39 (diff)
Properly clean up errors from exceptions. Properly catch exceptions when
creating ACL objects in Wallet::Server. Don't return the ACL object from the acl_create method of Wallet::Server -- it's a layering violation.
-rw-r--r--perl/Wallet/ACL.pm10
-rw-r--r--perl/Wallet/Object/Base.pm12
-rw-r--r--perl/Wallet/Server.pm30
3 files changed, 26 insertions, 26 deletions
diff --git a/perl/Wallet/ACL.pm b/perl/Wallet/ACL.pm
index 6226585..63e76aa 100644
--- a/perl/Wallet/ACL.pm
+++ b/perl/Wallet/ACL.pm
@@ -159,7 +159,7 @@ sub rename {
if ($@) {
$self->{error} = "cannot rename ACL $self->{id} to $name: $@";
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
$self->{dbh}->rollback;
return undef;
}
@@ -185,7 +185,7 @@ sub destroy {
if ($@) {
$self->{error} = "cannot destroy ACL $self->{id}: $@";
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
$self->{dbh}->rollback;
return undef;
}
@@ -214,7 +214,7 @@ sub add {
if ($@) {
$self->{error} = "cannot add $scheme:$identifier to $self->{id}: $@";
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
$self->{dbh}->rollback;
return undef;
}
@@ -245,7 +245,7 @@ sub remove {
my $entry = "$scheme:$identifier";
$self->{error} = "cannot remove $entry from $self->{id}: $@";
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
$self->{dbh}->rollback;
return undef;
}
@@ -275,7 +275,7 @@ sub list {
if ($@) {
$self->{error} = "cannot retrieve ACL $self->{id}: $@";
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
return (undef);
} else {
return @entries;
diff --git a/perl/Wallet/Object/Base.pm b/perl/Wallet/Object/Base.pm
index 389bbef..bc4bc26 100644
--- a/perl/Wallet/Object/Base.pm
+++ b/perl/Wallet/Object/Base.pm
@@ -143,7 +143,7 @@ sub log_action {
my $id = $self->{type} . ':' . $self->{name};
$self->{error} = "cannot update history for $id: $@";
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
$self->{dbh}->rollback;
return undef;
}
@@ -238,7 +238,7 @@ sub owner {
if ($@) {
$self->{error} = $@;
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
return undef;
}
return $self->_set_internal ('owner', $acl->id, $user, $host, $time);
@@ -254,7 +254,7 @@ sub acl {
if ($type !~ /^(get|store|show|destroy|flags)\z/) {
$self->{error} = "invalid ACL type $type";
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
return;
}
my $attr = "acl_$type";
@@ -264,7 +264,7 @@ sub acl {
if ($@) {
$self->{error} = $@;
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
return undef;
}
return $self->_set_internal ($attr, $acl->id, $user, $host, $time);
@@ -340,7 +340,7 @@ sub show {
if ($@) {
$self->{error} = "cannot retrieve data for ${type}:${name}: $@";
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
return undef;
}
my $output = '';
@@ -378,7 +378,7 @@ sub destroy {
if ($@) {
$self->{error} = "cannot destroy ${type}:${name}: $@";
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
$self->{dbh}->rollback;
return undef;
}
diff --git a/perl/Wallet/Server.pm b/perl/Wallet/Server.pm
index 7c1443c..76ec097 100644
--- a/perl/Wallet/Server.pm
+++ b/perl/Wallet/Server.pm
@@ -148,7 +148,7 @@ sub create {
if ($@) {
$self->{error} = $@;
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
return undef;
} else {
return $object;
@@ -168,7 +168,7 @@ sub retrieve {
if ($@) {
$self->{error} = $@;
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
return undef;
} else {
return $object;
@@ -209,7 +209,7 @@ sub acl_check {
if ($@) {
$self->{error} = $@;
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
return undef;
}
my $status = $acl->check ($self->{user});
@@ -321,8 +321,8 @@ sub destroy {
# ACL methods
##############################################################################
-# Create a new empty ACL in the database. Returns the new ACL object on
-# success and undef on failure, setting the internal error.
+# Create a new empty ACL in the database. Returns true on success and undef
+# on failure, setting the internal error.
sub acl_create {
my ($self, $name) = @_;
unless ($self->{admin}->check ($self->{user})) {
@@ -336,10 +336,10 @@ sub acl_create {
if ($@) {
$self->{error} = $@;
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
return undef;
} else {
- return $acl;
+ return 1;
}
}
@@ -364,11 +364,11 @@ sub acl_rename {
$self->acl_error ($id, 'rename');
return undef;
}
- my $acl = { Wallet::ACL->new ($id, $self->{dbh}) };
+ my $acl = eval { Wallet::ACL->new ($id, $self->{dbh}) };
if ($@) {
$self->{error} = $@;
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
return undef;
}
unless ($acl->rename ($name)) {
@@ -386,11 +386,11 @@ sub acl_destroy {
$self->acl_error ($id, 'destroy');
return undef;
}
- my $acl = { Wallet::ACL->new ($id, $self->{dbh}) };
+ my $acl = eval { Wallet::ACL->new ($id, $self->{dbh}) };
if ($@) {
$self->{error} = $@;
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
return undef;
}
unless ($acl->destroy ($self->{user}, $self->{host})) {
@@ -408,11 +408,11 @@ sub acl_add {
$self->acl_error ($id, 'add');
return undef;
}
- my $acl = { Wallet::ACL->new ($id, $self->{dbh}) };
+ my $acl = eval { Wallet::ACL->new ($id, $self->{dbh}) };
if ($@) {
$self->{error} = $@;
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
return undef;
}
unless ($acl->add ($scheme, $identifier, $self->{user}, $self->{host})) {
@@ -430,11 +430,11 @@ sub acl_remove {
$self->acl_error ($id, 'remove');
return undef;
}
- my $acl = { Wallet::ACL->new ($id, $self->{dbh}) };
+ my $acl = eval { Wallet::ACL->new ($id, $self->{dbh}) };
if ($@) {
$self->{error} = $@;
chomp $self->{error};
- $self->{error} =~ / at .*$/;
+ $self->{error} =~ s/ at .*$//;
return undef;
}
my $user = $self->{user};