summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2007-09-20 23:00:30 +0000
committerRuss Allbery <rra@stanford.edu>2007-09-20 23:00:30 +0000
commit523f7c3a446139bfb287a11f631f9526658bf116 (patch)
tree5094372890a76549c4011031779b4344cdcba4fa
parent516744caf3f0a46bf56528bdabb2128fef791327 (diff)
Take multiple values in the attr() method and convert it to a reference
to an array internally so that the callers don't have to be aware of the internal API.
-rw-r--r--perl/Wallet/Server.pm21
-rwxr-xr-xperl/t/server.t12
2 files changed, 16 insertions, 17 deletions
diff --git a/perl/Wallet/Server.pm b/perl/Wallet/Server.pm
index b646eb0..138a576 100644
--- a/perl/Wallet/Server.pm
+++ b/perl/Wallet/Server.pm
@@ -265,15 +265,15 @@ sub acl {
# Retrieves or sets an attribute on an object.
sub attr {
- my ($self, $type, $name, $attr, $values) = @_;
+ my ($self, $type, $name, $attr, @values) = @_;
undef $self->{error};
my $object = $self->retrieve ($type, $name);
return undef unless defined $object;
my $user = $self->{user};
my $host = $self->{host};
- if (defined $values) {
+ if (@values) {
return unless $self->acl_check ($object, 'setattr');
- my $result = $object->attr ($attr, $values, $user, $host);
+ my $result = $object->attr ($attr, [ @values ], $user, $host);
$self->error ($object->error) unless $result;
return $result;
} else {
@@ -713,25 +713,24 @@ be aware that anyone with show access to an object can see the membership of
ACLs associated with that object through the show() method). Returns the
human-readable description on success and undef on failure.
-=item attr(TYPE, NAME, ATTRIBUTE [, VALUES])
+=item attr(TYPE, NAME, ATTRIBUTE [, VALUE ...])
Sets or retrieves a given object attribute. Attributes are used to store
backend-specific information for a particular object type and ATTRIBUTE must
be an attribute type known to the underlying object implementation.
-If VALUES is not given, returns the values of that attribute, if any, as a
+If VALUE is not given, returns the values of that attribute, if any, as a
list. On error, returns the empty list. To distinguish between an error
and an empty return, call error() afterwards. It is guaranteed to return
undef unless there was an error. To retrieve an attribute setting, the user
must be authorized by the ADMIN ACL, the show ACL if set, or the owner ACL
if the show ACL is not set.
-If VALUES is given, sets the given ATTRIBUTE values to VALUES, which must be
-a reference to an array (even if only one value is being set). Pass a
-reference to an empty array to clear the attribute values. Returns true on
-success and false on failure. To set an attribute value, the user must be
-authorized by the ADMIN ACL, the store ACL if set, or the owner ACL if the
-store ACL is not set.
+If VALUE is given, sets the given ATTRIBUTE values to VALUE, which is one or
+more attribute values. Pass the empty string as the only VALUE to clear the
+attribute values. Returns true on success and false on failure. To set an
+attribute value, the user must be authorized by the ADMIN ACL, the store ACL
+if set, or the owner ACL if the store ACL is not set.
=item create(TYPE, NAME)
diff --git a/perl/t/server.t b/perl/t/server.t
index a06f4c0..3da5461 100755
--- a/perl/t/server.t
+++ b/perl/t/server.t
@@ -186,7 +186,7 @@ is ($server->error, undef, ' and still no error');
is ($server->attr ('base', 'service/admin', 'foo'), undef,
'Getting an attribute fails');
is ($server->error, 'unknown attribute foo', ' but called the method');
-is ($server->attr ('base', 'service/admin', 'foo', [ 'foo' ]), undef,
+is ($server->attr ('base', 'service/admin', 'foo', 'foo'), undef,
' and setting an attribute fails');
is ($server->error, 'unknown attribute foo', ' and called the method');
@@ -445,7 +445,7 @@ is ($show, $expected, ' and show an object we own');
is ($server->attr ('base', 'service/user1', 'foo'), undef,
' and getting an attribute fails');
is ($server->error, 'unknown attribute foo', ' but calls the method');
-is ($server->attr ('base', 'service/user1', 'foo', [ 'foo' ]), undef,
+is ($server->attr ('base', 'service/user1', 'foo', 'foo'), undef,
' and setting an attribute fails');
is ($server->error, 'unknown attribute foo', ' but calls the method');
@@ -466,7 +466,7 @@ is ($server->attr ('base', 'service/user2', 'foo'), undef,
is ($server->error,
"$user1 not authorized to get attributes for base:service/user2",
' with the right error');
-is ($server->attr ('base', 'service/user2', 'foo', [ 'foo' ]), undef,
+is ($server->attr ('base', 'service/user2', 'foo', ''), undef,
' and set attributes');
is ($server->error,
"$user1 not authorized to set attributes for base:service/user2",
@@ -523,10 +523,10 @@ is ($server->error, "$user1 not authorized to destroy base:service/both",
is ($server->attr ('base', 'service/both', 'foo'), undef,
'Getting an attribute fails');
is ($server->error, 'unknown attribute foo', ' but calls the method');
-is ($server->attr ('base', 'service/both', 'foo', [ 'foo' ]), undef,
+is ($server->attr ('base', 'service/both', 'foo', ''), undef,
' and setting an attribute fails');
is ($server->error, 'unknown attribute foo', ' but calls the method');
-is ($server->attr ('base', 'service/admin', 'foo', [ 'foo' ]), undef,
+is ($server->attr ('base', 'service/admin', 'foo', ''), undef,
' but setting an attribute on service/admin fails');
is ($server->error, 'unknown attribute foo', ' and calls the method');
is ($server->attr ('base', 'service/admin', 'foo'), undef,
@@ -604,7 +604,7 @@ is ($server->attr ('base', 'service/both', 'foo'), undef,
is ($server->error,
"$user2 not authorized to get attributes for base:service/both",
' with the right error');
-is ($server->attr ('base', 'service/both', 'foo', [ 'foo' ]), undef,
+is ($server->attr ('base', 'service/both', 'foo', 'foo'), undef,
' but setting an attribute fails');
is ($server->error, 'unknown attribute foo', ' but calls the method');
is ($server->destroy ('base', 'service/both'), 1, ' and we can destroy it');