<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">NAME
    MooX::Struct - make simple lightweight record-like structures that make
    sounds like cows

SYNOPSIS
     use MooX::Struct
        Point   =&gt; [ 'x', 'y' ],
        Point3D =&gt; [ -extends =&gt; ['Point'], 'z' ],
     ;
 
     my $origin = Point3D-&gt;new( x =&gt; 0, y =&gt; 0, z =&gt; 0 );

DESCRIPTION
    MooX::Struct allows you to create cheap struct-like classes for your
    data using Moo.

    While similar in spirit to MooseX::Struct and Class::Struct,
    MooX::Struct has a somewhat different usage pattern. Rather than
    providing you with a "struct" keyword which can be used to define
    structs, you define all the structs as part of the "use" statement. This
    means they happen at compile time.

    A struct is just an "anonymous" Moo class. MooX::Struct creates this
    class for you, and installs a lexical alias for it in your namespace.
    Thus your module can create a "Point3D" struct, and some other module
    can too, and they won't interfere with each other. All struct classes
    inherit from MooX::Struct; and MooX::Struct provides a useful method:
    "object_id" (see Object::ID).

    Arguments for MooX::Struct are key-value pairs, where keys are the
    struct names, and values are arrayrefs.

     use MooX::Struct
        Person   =&gt; [qw/ name address /],
        Company  =&gt; [qw/ name address registration_number /];

    The elements in the array are the attributes for the struct (which will
    be created as read-only attributes), however certain array elements are
    treated specially.

    *   As per the example in the "SYNOPSIS", "-extends" introduces a list
        of parent classes for the struct. If not specified, then classes
        inherit from MooX::Struct itself.

        Structs can inherit from other structs, or from normal classes. If
        inheriting from another struct, then you *must* define both in the
        same "use" statement.

         # Not like this.
         use MooX::Struct Point   =&gt; [ 'x', 'y' ];
         use MooX::Struct Point3D =&gt; [ -extends =&gt; ['Point'], 'z' ];
 
         # Like this.
         use MooX::Struct
            Point   =&gt; [ 'x', 'y' ],
            Point3D =&gt; [ -extends =&gt; ['Point'], 'z' ],
         ;

    *   If an attribute name is followed by a coderef, this is installed as
        a method instead.

         use MooX::Struct
            Person =&gt; [
               qw( name age sex ),
               greet =&gt; sub {
                  my $self = shift;
                  CORE::say "Hello ", $self-&gt;name;
               },
            ];

        But if you're defining methods for your structs, then you've
        possibly missed the point of them.

    *   If an attribute name is followed by an arrayref, these are used to
        set the options for the attribute. For example:

         use MooX::Struct
            Person  =&gt; [ name =&gt; [ is =&gt; 'ro', required =&gt; 1 ] ];

    *   Attribute names may be "decorated" with prefix and postfix "sigils".
        The prefix sigils of "@" and "%" specify that the attribute isa
        arrayref or hashref respectively. (Blessed arrayrefs and hashrefs
        are accepted; as are objects which overload "@{}" and "%{}".) The
        prefix sigil "$" specifies that the attribute value must not be an
        unblessed arrayref or hashref. The postfix sigil "!" specifies that
        the attribute is required.

         use MooX::Struct
            Person  =&gt; [qw( $name! @children )];

         Person-&gt;new();         # dies, name is required
         Person-&gt;new(           # dies, children should be arrayref
            name     =&gt; 'Bob',
            children =&gt; 2,
         );

    Prior to the key-value list, some additional flags can be given. These
    begin with hyphens. The flag "-rw" indicates that attributes should be
    read-write rather than read-only.

     use MooX::Struct -rw,
        Person =&gt; [
           qw( name age sex ),
           greet =&gt; sub {
              my $self = shift;
              CORE::say "Hello ", $self-&gt;name;
           },
        ];

    Flags "-trace" and "-deparse" may be of use debugging.

BUGS
    Please report any bugs to
    &lt;http://rt.cpan.org/Dist/Display.html?Queue=MooX-Struct&gt;.

SEE ALSO
    Moo, MooseX::Struct, Class::Struct.

AUTHOR
    Toby Inkster &lt;tobyink@cpan.org&gt;.

COPYRIGHT AND LICENCE
    This software is copyright (c) 2012 by Toby Inkster.

    This is free software; you can redistribute it and/or modify it under
    the same terms as the Perl 5 programming language system itself.

DISCLAIMER OF WARRANTIES
    THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
    WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
    MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

</pre></body></html>