Skip to content

Commit

Permalink
Moosify.
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Jan 15, 2018
1 parent d2b9a55 commit 0ce9a4b
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions Lotto.pm
Expand Up @@ -4,16 +4,28 @@ use strict;
use warnings;
use 5.010;

use Moose;

has type => (
isa => 'Str',
is => 'ro',
);

has count => (
isa => 'Int',
is => 'ro',
);

our $config;

sub play {
my $self = shift;

my $lotto = $config->{$self->{type}};
my $lotto = $config->{$self->type};

my @results;

for (1 .. $self->{count}) {
for (1 .. $self->count) {
my @nums;
foreach my $set (@$lotto) {
my %tries;
Expand Down Expand Up @@ -41,9 +53,18 @@ sub parse_config {
}
}

sub new {
around BUILDARGS => sub {
my $orig = shift;
my $class = shift;

if (@_ == 1 and ref $_[0] eq 'HASH') {
return $class->$orig(@_);
}

if (@_ == 4) {
return $class->$orig(@_);
}

parse_config() unless keys %$config;

my ($type, $count) = qw[lotto 1];
Expand Down Expand Up @@ -86,11 +107,11 @@ sub new {
die join "\n", @errs;
}

return bless {
return $class->$orig({
type => $type,
count => $count,
}, $class;
}
});
};

1;

Expand Down

0 comments on commit 0ce9a4b

Please sign in to comment.