Help language development. Donate to The Perl Foundation

Attribute::Predicate zef:lizmat last updated on 2021-11-07
[![Actions Status](](


Attribute::Predicate - add "is predicate" trait to Attributes


    use Attribute::Predicate;

    class Foo {
        has $.bar is predicate;         # adds method "has-bar"
        has $.baz is predicate<bazzy>;  # adds method "bazzy"
    } => 42).has-bar;    # True => 42).bazzy;      # False


This module adds a `is predicate` trait to `Attributes`. It is similar in function to the "predicate" option of Perl's `Moo` and `Moose` object systems.

If specified without any additional information, it will create a method with the name "has-{}". If a specific string is specified, then it will create the method with that given name.

The method in question will return a `Bool` indicating whether the attribute has a defined value.


Elizabeth Mattijsen <[email protected]>

Source can be located at: . Comments and Pull Requests are welcome.


Copyright 2018, 2019, 2021 Elizabeth Mattijsen

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.