aboutsummaryrefslogtreecommitdiff
path: root/challenge-027/colin-crain/perl5/HistoryThing.pm
blob: 163478de2f789a015b1b787cbcb8da4f24a17ec4 (plain)
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
41
42
43
44
45
46
47
48
49
#       HistoryThing
#
#       object
#
#
#       (c) 2019 colin crain
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##

package HistoryThing;

use Moo;
use feature ":5.26";
our $VERSION = "0.01";


## attributes
has 'x' => (
    is => 'rw',
    trigger => sub {
        my ($self, $new) = @_;
        push $self->_history->{'x'}->@*, $new;
    }
);

has 'y' => (
    is => 'rw',
    trigger => sub {
        my ($self, $new) = @_;
        push $self->_history->{'y'}->@*, $new;
    }
);

## pubic methods
sub get_hist {
    my ($self, $var) = @_;
    return (join ', ', $self->_history->{$var}->@*);

};

## private attribute (hash)
has _history => (
    is => 'rw',
    default => sub {
        return { 'x' => [], 'y' => [] };
    },
);


1;