Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit e83f10ef79d2df84086b9ce2061ce7c3f5d38e74 @ctfouts ctfouts committed Mar 20, 2012
Showing with 129 additions and 0 deletions.
  1. +1 −0 .proverc
  2. +9 −0 dist.ini
  3. +9 −0 lib/Xape.pm
  4. +14 −0 lib/Xape/Charset.pm
  5. +22 −0 lib/Xape/Charset/he.pm
  6. +42 −0 lib/Xape/Enumerator.pm
  7. +32 −0 t/001-enum.t
@@ -0,0 +1 @@
+-l
@@ -0,0 +1,9 @@
+name = Xape
+author = Clay Fouts <cfouts@khephera.net>
+license = Perl_5
+copyright_holder = Clay Fouts
+copyright_year = 2012
+
+version = 0.001
+
+[@Basic]
@@ -0,0 +1,9 @@
+package Xape::Enumerator;
+
+use Any::Moose;
+use Method::Signatures;
+
+__PACKAGE__->meta->make_immutable;
+no Any::Moose;
+
+1;
@@ -0,0 +1,14 @@
+package Xape::Charset;
+
+use Any::Moose qw(Role);
+use Method::Signatures;
+
+requires 'charmap';
+
+method lookup($in) {
+ return $self->charmap->{$in};
+}
+
+no Any::Moose;
+
+1;
@@ -0,0 +1,22 @@
+package Xape::Charset::he;
+
+use Any::Moose;
+use utf8;
+
+has 'charmap' => (
+ is => 'ro',
+ isa => 'HashRef',
+ default => sub {
+ return {
+ a => 'A',
+ b => 'B',
+ c => 'C',
+ };
+ },
+);
+
+with 'Xape::Charset';
+
+__PACKAGE__->meta->make_immutable;
+no Any::Moose;
+1;
@@ -0,0 +1,42 @@
+package Xape::Enumerator;
+
+use Any::Moose;
+use Method::Signatures;
+use Xape::Charset;
+
+has 'charset' => (
+ is => 'ro',
+ isa => 'Xape::Charset',
+ required => 1,
+);
+
+around BUILDARGS => sub {
+ my $orig = shift;
+ my $class = shift;
+ return 1 unless $class;
+
+ if (@_ == 1) {
+ local $_[0] = $_[0];
+ unless (ref $_[0]) {
+ my $package_name = "Xape::Charset::$_[0]";
+ eval {
+ require $package_name;
+ import $package_name;
+ };
+ $_[0] = $package_name->new;
+ }
+ return $class->$orig(charset => $_[0]);
+
+ }
+ else {
+ return $class->$orig(@_);
+ }
+};
+
+method enumerate(Str $input) {
+ return undef;
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
@@ -0,0 +1,32 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More;
+
+BEGIN {
+ use_ok 'Xape::Enumerator';
+ use_ok 'Xape::Charset';
+ use_ok 'Xape::Charset::he';
+}
+
+my $charset = Xape::Charset::he->new();
+isa_ok $charset, 'Xape::Charset::he';
+is $charset->lookup('a'), 'A';
+is $charset->lookup('b'), 'B';
+isnt $charset->lookup('a'), 'B';
+isnt $charset->lookup('A'), 'a';
+
+my $enum;
+$enum = Xape::Enumerator->new(charset => $charset);
+isa_ok $enum, 'Xape::Enumerator';
+
+$enum = Xape::Enumerator->new($charset);
+isa_ok $enum, 'Xape::Enumerator';
+
+$enum = Xape::Enumerator->new('he');
+isa_ok $enum, 'Xape::Enumerator';
+
+can_ok $enum, qw(enumerate);
+
+done_testing;

0 comments on commit e83f10e

Please sign in to comment.