File: Change.pm

package info (click to toggle)
libur-perl 0.470%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,192 kB
  • sloc: perl: 61,814; javascript: 255; xml: 108; sh: 13; makefile: 9
file content (40 lines) | stat: -rw-r--r-- 1,010 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package Vending::Command::Service::Add::Change;
use strict;
use warnings;

use Vending;
class Vending::Command::Service::Add::Change {
    is => 'Vending::Command::Service::Add',
    doc => 'Add change to the vending machine',
    has => [
        name => { is => 'String', doc => 'Name of the coin' },
        count => { is => 'Integer', doc => 'How many you are adding' },
    ],
};

sub execute {
    my $self = shift;

    my $machine = $self->machine();

    my $coin_kind = Vending::CoinType->get(name => $self->name);
    unless ($coin_kind) {
        $self->error_message($self->name." is not a valid coin name");
        return;
    }

    my $change_disp = $machine->change_dispenser;
    unless ($change_disp) {
        die "Couldn't retrieve money location for 'change'";
    }

    my $count = $self->count;
    while($count--) {
        my $coin = $change_disp->add_item(subtype_name => 'Vending::Coin', type_id => $coin_kind->type_id, machine_id => $self);
        1;
    }

    return 1;
}
1;