Acme-Buga
view release on metacpan or search on metacpan
lib/Acme/Buga.pm view on Meta::CPAN
# original idea from @PACMAN, thank you man!
our $VERSION = '1.002';
use Convert::BaseN;
use Exporter 'import';
our @EXPORT_OK = qw/buga/;
# constants
use constant BUGA_LIST => [qw/Buga bUga buGa BugA buga BUGA BUga buGA/];
use constant OCTALS => {map{ BUGA_LIST->[$_] => $_ } 0 .. 7};
sub new {
my $class = shift;
my $args = (@_ % 2 == 0) ? {@_} : undef;
return bless {_value => $args->{value} || undef}, $class;
}
# accessors
sub base8 {
lib/Acme/Buga.pm view on Meta::CPAN
sub value {
$_[0]->{_value} = $_[1] if $_[1];
return $_[0]->{_value};
}
# methods
sub encode {
my ($self, $value) = @_;
my $en = $self->base8->encode( $value || $self->value );
$en =~ s/\D//g;
return join ' ', map { BUGA_LIST->[$_]} split(//,$en);
}
sub decode {
my ($self, $value) = @_;
$value = $value ? $value : $self->value;
$value = join '', map { OCTALS->{$_} } split(/ /, $value);
return $self->base8->decode($value .'==');
}
sub buga {
return __PACKAGE__->new(value => $_[0]);
}
1;
__END__
( run in 1.114 second using v1.01-cache-2.11-cpan-49f99fa48dc )