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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| package Decode;
#moosebis/Decode.pm
use Moose;
##############################################################
has 'tab_fonction' => (
isa => 'ArrayRef',
is => 'ro',
#lazy => 1,
#default => 'inconnu'
default => sub { my $self = shift; return ['nom', 'untruc', 'deuxtruc', 'troistruc', 'quatruc']; }
);
##############################################################
has 'untruc' => (
isa => 'Str',
is => 'rw',
lazy => 1,
default => '0'
);
##############################################################
has 'nom' => (
isa => 'Str',
is => 'rw',
lazy => 1,
default => '0'
);
##############################################################
has 'deuxtruc' => (
isa => 'Str',
is => 'rw',
lazy => 1,
default => '0'
);
##############################################################
has 'troistruc' => (
isa => 'Str',
is => 'rw',
lazy => 1,
default => '0'
);
##############################################################
has 'quatruc' => (
isa => 'Str',
is => 'rw',
lazy => 1,
default => '0'
);
##############################################################
has 'strcode' => (
isa => 'Str',
is => 'ro',
);
##############################################################
sub affiche_at {
my $self = shift;
my @tab = $self->tab_fonction;
my $longtab = @{$tab[0]};
my $retour = 0;
for (my $var = 0; $var < $longtab; $var++) {
print ${tab}[0][$var]."\n";
}
return $retour;
}
##############################################################
sub present {
my $self = shift;
my $code = shift;
my @tab = $self->tab_fonction;
my $longtab = @{$tab[0]};
my $retour = 0;
for (my $var = 0; $var < $longtab; $var++) {
if ( ($code eq ${tab}[0][$var]) ) {$retour = 1; last}
}
return $retour;
}
##############################################################
##############################################################
sub decode {
my $self = shift;
my $code = shift;
my $str = $self->strcode;
my $search = '\['."$code".'\%(.+?)\]';
if ($str =~ m/$search/) {
$self->$code($1);
}
}
##############################################################
no Moose;
__PACKAGE__->meta->make_immutable; |
Partager