burguillos.info/lib/BurguillosInfo/Ad.pm

55 lines
803 B
Perl
Raw Normal View History

2023-08-20 13:51:32 +02:00
package BurguillosInfo::Ad;
use v5.36.0;
use strict;
use warnings;
use feature 'signatures';
use Moo::Role;
2023-08-21 14:10:18 +02:00
has alternative => (
is => 'rw'
);
sub max_alternative {
return 0;
}
sub regenerate_alternative($self) {
$self->alternative(int(rand() * ($self->max_alternative+1)));
}
sub weight {
return 25;
2023-08-20 13:51:32 +02:00
}
sub seconds {
2023-08-21 14:10:18 +02:00
return 3;
2023-08-20 13:51:32 +02:00
}
2023-08-21 00:58:11 +02:00
sub serialize ($self) {
return {
id => $self->id,
img => $self->img,
text => $self->text,
href => $self->href,
seconds => $self->seconds,
};
}
{
my %instances;
sub instance ($class) {
if ( !defined $instances{$class} ) {
$instances{$class} = $class->new;
}
return $instances{$class};
}
}
requires 'id is_active img text href';
2023-08-20 13:51:32 +02:00
1;