73 lines
1.3 KiB
Perl
73 lines
1.3 KiB
Perl
package MyRedland::Products;
|
|
|
|
use v5.34.1;
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use utf8;
|
|
|
|
use MyRedland::Product;
|
|
|
|
use Moo;
|
|
use Types::Standard qw/Str Int/;
|
|
use Params::ValidationCompiler qw/validation_for/;
|
|
|
|
has all => (
|
|
is => 'lazy'
|
|
);
|
|
|
|
has _all_by_id => (
|
|
is => 'lazy'
|
|
);
|
|
|
|
sub _build_all {
|
|
my $self = shift;
|
|
return [
|
|
MyRedland::Product->new(
|
|
id => 'MONTH',
|
|
name => 'Pago mensual',
|
|
description => 'Paga mes a mes tu subscripción al servidor principal.',
|
|
price => 300,
|
|
period => 'mes',
|
|
),
|
|
MyRedland::Product->new(
|
|
id => 'PAIRMONTHLY',
|
|
name => 'Pago mensual en pareja',
|
|
description => 'Paga mes a mes tu suscripción y la de otra persona, os ahorráis 1€/mes entre los dos.',
|
|
price => 500,
|
|
period => 'mes',
|
|
),
|
|
MyRedland::Product->new(
|
|
id => 'YEAR',
|
|
name => 'Pago anual',
|
|
description => 'Paga anualmente tu subscripción al servidor principal, pagas 1.92€/m, 1.08€/m menos, te ahorras 13€/año.',
|
|
price => 2300,
|
|
period => 'año',
|
|
),
|
|
];
|
|
}
|
|
|
|
sub _build__all_by_id {
|
|
my $self = shift;
|
|
my $all = $self->all;
|
|
return {
|
|
(map { $_->id => $_ } @$all),
|
|
};
|
|
}
|
|
|
|
{
|
|
my $validator = validation_for(
|
|
params => {
|
|
id => { type => Str },
|
|
}
|
|
);
|
|
sub find_by_id {
|
|
my $self = shift;
|
|
my %params = $validator->(@_);
|
|
my $id = $params{id};
|
|
return $self->_all_by_id->{$id};
|
|
}
|
|
}
|
|
1;
|