Skip to content
This repository was archived by the owner on Aug 28, 2025. It is now read-only.

Commit 990199f

Browse files
committed
Add RevBank::Accounts::delete
1 parent 8c06fe8 commit 990199f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/RevBank/Accounts.pm

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,25 @@ sub create($account) {
8080
return $account;
8181
}
8282

83+
sub delete($account) {
84+
die "No such account" if RevBank::Accounts::is_special $account;
85+
86+
my $user_found = 0;
87+
rewrite $filename, sub($line) {
88+
my @a = split " ", $line;
89+
if (lc $a[0] ne lc $account) {
90+
return $line;
91+
}
92+
if ($a[1] != 0) {
93+
die "Account $account still has balance";
94+
}
95+
$user_found = 1;
96+
return "";
97+
};
98+
99+
die "No such account" if not $user_found;
100+
}
101+
83102
sub update($account, $delta, $transaction_id) {
84103
$account = assert_account($account);
85104

lib/RevBank/Accounts.pod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ Creates an account with that name and a balance of zero. The name must not alrea
126126

127127
After updating the file, calls the C<account_created> hook with the account name.
128128

129+
=head3 delete($name)
130+
131+
Deletes an account.
132+
133+
Special accounts may not be deleted via this method. The account must have a balance of 0.00.
134+
129135
=head3 update($name, $delta, $transaction_id)
130136

131137
Given the relative change (C<$delta>), updates the user balance for an account.

0 commit comments

Comments
 (0)