View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Quim Rovira > ExtJS-AutoForm-Moose > ExtJS::AutoForm::Moose::Types



Annotate this POD


New  2
Open  0
View/Report Bugs


ExtJS::AutoForm::Moose::Types - Manage extjs form generation for Moose types


Those are in fact the current type reflections implemented, except for enum, which is treated in a special way so far:

    reflect 'Any'  => extjs { {
        xtype => "displayfield",
        fieldLabel=> "Unsupported field type"
    } };

    reflect 'Str'  => extjs { {
        xtype => "textfield",
        value => \&ExtJS::AutoForm::Moose::Types::value_or_default
    } };

    reflect 'Num'  => extjs { {
        xtype => "numberfield",
        allowDecimals => JSON::Any::true,
        value => \&ExtJS::AutoForm::Moose::Types::value_or_default
    } };

    reflect 'Int'  => extjs { {
        xtype => "numberfield",
        allowDecimals => JSON::Any::false,
        value => \&ExtJS::AutoForm::Moose::Types::value_or_default
    } };

    reflect 'Bool' => extjs { {
        xtype => "checkbox",
        checked => \&ExtJS::AutoForm::Moose::Types::value_or_default_bool
    } };


This module does two things: hold the registry of known type contraints reflections, and provide a bit of curry to ease adding reflections for new types based on their type name.

Syntax curry

reflect 'type_name' => extjs { code returning a hash template }

Create a new moose type constraint to extjs field association.

The template parameter must be specified as a perl function that returns a hash that will be, at some point, encoded as JSON and sent to a browser. You can use callbacks as values on this hash, which will be called and it's result used as the generated key value (See callbacks in "TEMAPLTE FORMAT" below).

Template format

The template format is the one used by ExtJS Component class creation. This means it does all it's job using xtypes and does not use any javascript functions.

Customizing tamplate values using callbacks

Any template hash value can be a callback instead of a plain value, which allows further customization of the generated extjs description.

Those callbacks receive two parameters: the object instance (undef when generation has been called statically), and the Moose::Meta::Attribute instance for that attribute.


    sub enum_values($$) {
        my ($obj,$attribute) = @_;
        return $attribute->type_constraint->values;

See "REFLECTION HELPERS" below for a list of helper callbacks provided by default.

Javascript functions on the generated result?

Using javascript isn't straight-forward because the generated result is usually encoded as JSON, which by itself does not support javascript functions.

In those cases you need to use javascript functions, you've got a few options:


The following subroutines are provided as helpers for common checks and transformations used on the ExtJS templates.


Returns the current value of this attribute for the given object, or it's default value if reflection was done directly on the class


Does the same as the previous helper, but it returns a JSON boolean value suitable for JSON::Any encoding


Returns a JSON true value when this attribute is required, false otherwise

sub required_attribute_bool($$) {
    my ($obj,$attribute) = @_;
    return $attribute->is_required ? JSON::Any::true : JSON::Any::false;

Returns an array containing the enum-type attribute values. See Moose::Meta::TypeConstraint::Enum.


Quim Rovira, quim at


Please report any bugs or feature requests to bug-moosex-extjs-reflection at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc ExtJS::AutoForm::Moose::Types

You can also look for information at:



Copyright 2011 Quim Rovira.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.

ExtJS trademarks are property of Sencha Labs

syntax highlighting: