Skip to content

Instantly share code, notes, and snippets.

@timo
Forked from samuraisam/my_eq.pl
Last active December 18, 2015 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timo/5810910 to your computer and use it in GitHub Desktop.
Save timo/5810910 to your computer and use it in GitHub Desktop.
class PB::SubMsg {
}
class PB::Option {
has Str $.name;
has $.constant;
has PB::SubMsg $.sub-message;
method gist() {
"<Option {$.name}={$.constant || 'Any'}>"
}
}
multi infix:<eq>(PB::Option $a, PB::Option $b) {
return
[&&] ($a.name eq $b.name),
($a.constant // "") eq ($b.constant // ""),
($a.sub-message // "") eq ($b.sub-message // "");
}
use Test;
plan 3;
my $o = PB::Option.new(name=>'hello');
my $oo = PB::Option.new(name=>'hello');
my $a = PB::Option.new(:name<hello>, :constant<greetings>);
my $aa = PB::Option.new(:name<hello>, :constant<greetings>);
ok $o eq $oo;
ok $a eq $aa;
nok $o eq $a;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment