The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

MooX::SugarFactory - build a library of syntax-sugared Moo classes

VERSION

version 0.213360

SYNOPSIS

Declare classes in a library that will export sugar.

    package My::SugarLib;
    use MooX::SugarFactory;
    
    class "My::Moo::Object" => (
        has => [ plus => ( is => 'ro' ) ],
        has => [ more => ( is => 'ro' ) ],
    );
    
    class "My::Moose::ThingRole" => (
        has     => [ contains => ( is => 'ro' ) ],
        has     => [ metaa    => ( is => 'ro' ) ],
    );
    
    class "My::Moose::Thing" => ( with => ThingRole(), extends => Object() );

Use class library to export sugar for object construction and class checking.

    package My::Code;
    use My::SugarLib;
    
    my $obj = object plus => "some", more => "data";
    die if !$obj->isa( Object );
    die if !$obj->plus eq "some";
    
    my $obj2 = thing contains => "other", meta => "data",    #
      plus => "some", more => "data";
    
    die if !$obj2->isa( Thing );
    die if !$obj2->does( ThingRole );
    die if !$obj2->isa( Object );
    die if !$obj2->meta eq "data";

AUTHOR

Christian Walde <walde.christian@gmail.com>

COPYRIGHT AND LICENSE

Christian Walde has dedicated the work to the Commons by waiving all of his or her rights to the work worldwide under copyright law and all related or neighboring legal rights he or she had in the work, to the extent allowable by law.

Works under CC0 do not require attribution. When citing the work, you should not imply endorsement by the author.