Skip to content

Instantly share code, notes, and snippets.

/foo.pl Secret

Created August 18, 2015 09:28
Show Gist options
  • Save anonymous/fe763c0a65ac45b8eb8a to your computer and use it in GitHub Desktop.
Save anonymous/fe763c0a65ac45b8eb8a to your computer and use it in GitHub Desktop.
hardoded builder
#!/usr/bin/env perl
use strict;
use warnings;
use Moose::Util::TypeConstraints;
use MooseX::Types::Moose qw/ ArrayRef Str/;
coerce Str,
from ArrayRef,
via {
my $data = $_;
my @attribs = split "/","foo/bar/baz";
my $i = 0;
return join ("",map {
"<$_>$data->[$i++]";
} @attribs) . join ("",map { "</$_>" } reverse @attribs);
};
{
package Foo;
use Moose;
has "elem" => ( is => "rw", isa => "Str", coerce => 1, );
1;
}
## main
my $f = Foo->new(elem => ["Ted", "Tampa, FL", 100]);
print $f->elem();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment