Skip to content

Instantly share code, notes, and snippets.

@moltar
Created November 17, 2012 02:38
Show Gist options
  • Save moltar/4092831 to your computer and use it in GitHub Desktop.
Save moltar/4092831 to your computer and use it in GitHub Desktop.
package WWW::MenuGrinder::Plugin::BoolMethod;
# ABSTRACT: WWW::MenuGrinder plugin that does boolean checks on items.
use Moose;
use Carp;
with 'WWW::MenuGrinder::Role::ItemMogrifier';
sub item_mogrify {
my ($self, $item) = @_;
for my $bool (qw/is_true is_false/) {
if (exists $item->{$bool}) {
my @checks
= ref($item->{$bool})
? @{ $item->{$bool} }
: $item->{$bool};
for my $check (@checks) {
if (!$self->$bool($check)) {
return ();
}
}
}
}
return $item;
}
sub is_true {
my ($self, $check) = @_;
croak "Method $check is not defined"
unless $self->grinder->can($check);
return 1 if $self->grinder->$check;
return 0;
}
sub is_false {
my ($self, $check) = @_;
return !$self->is_true($check);
}
__PACKAGE__->meta->make_immutable;
no Moose;
1;
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment