burguillos.info/lib/BurguillosInfo/Ad.pm

55 lines
824 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;
use Scalar::Util qw/blessed/;
2023-08-20 13:51:32 +02:00
2023-08-21 14:10:18 +02:00
has alternative => (
is => 'rw'
);
sub clone($self) {
my $class = blessed $self;
$self = $class->new;
2023-08-23 16:34:12 +02:00
$self->alternative(rand());
return $self;
2023-08-21 14:10:18 +02:00
}
sub weight {
return 25;
2023-08-20 13:51:32 +02:00
}
sub seconds($self) {
2023-08-21 20:56:32 +02:00
return 5;
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;