MooseX::MojoControllerExposingAttributes::Trait::Attribute - trait used to expose attribute to Mojolicious


    package MyApp::Controller::Example;
    use MooseX::MojoControllerExposingAttributes;


    has some_attribute => (
        is     => 'ro',
        traits => ['ExposeMojo'],

    # then later in a template: <%= ctrl->some_attribute %>


This class is an attribute trait that can be applied with ExposeMojo.

Applying this trait to an attribute within a Mojolicious::Controller subclass allows reading of that attribute from within a Mojolicious template by calling the corresponding method name on the ctrl helper.

In order to this to work you must also correctly setup the metaclass of the controller (usually by simply doing a use MooseX::MojoControllerExposingAttributes; within that controller class) and load the Mojolicious::Plugin::ExposeControllerMethod plugin within your Mojolicious application to provide the ctrl helper.



Provide an alternative name this attribute should be exposed as

    # expose the rose attribute so it can be called via ctrl->other_name
    # rather than ctrl->rose
    has rose => (
        is                => 'ro',
        traits            => ['ExposeMojo'],
        expose_to_mojo_as => 'other_name',

By default if expose_to_mojo_as isn't provided the attribute will be exposed as a method with the same name as the attribute (worth noting: this is not necessarily the same as the name of the reader method that you'd normally use to access the attribute if you've defined that to be different to the attribute name.)