Created
November 5, 2012 21:15
-
-
Save tobyink/4020381 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| package Param; | |
| use Moo; | |
| use overload q[""] => q[to_string]; | |
| has [qw/ type name /] => (is => 'ro'); | |
| sub BUILDARGS { | |
| my $class = shift; | |
| if (@_==1 and not ref $_[0] and $_[0] =~ /^([\$\%\@])(.+)$/) { | |
| return +{ type => $1, name => $2 }; | |
| } | |
| return $class->SUPER::BUILDARGS(@_); | |
| } | |
| sub to_string { | |
| my $self = shift; | |
| join q(), $self->type, $self->name; | |
| } | |
| } | |
| use feature qw(say); | |
| my $param = Param->new('$foo'); | |
| say $param->type; | |
| say $param->name; | |
| say $param; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment