Skip to content

Instantly share code, notes, and snippets.

@tobyink
Created November 5, 2012 21:15
Show Gist options
  • Select an option

  • Save tobyink/4020381 to your computer and use it in GitHub Desktop.

Select an option

Save tobyink/4020381 to your computer and use it in GitHub Desktop.
{
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