package HTML::FormFu::Element; use Moose; with 'HTML::FormFu::Role::Render', 'HTML::FormFu::Role::FormAndElementMethods', 'HTML::FormFu::Role::HasParent'; use HTML::FormFu::Attribute qw( mk_attrs mk_attr_accessors mk_output_accessors mk_inherited_accessors mk_inherited_merging_accessors ); use HTML::FormFu::ObjectUtil qw( load_config_file load_config_filestem populate form stash parent get_parent ); use HTML::FormFu::Util qw( require_class xml_escape process_attrs ); use Clone (); use Scalar::Util qw( refaddr weaken ); use Carp qw( croak ); use overload ( 'eq' => '_string_equals', '==' => '_object_equals', '""' => sub { return shift->render }, bool => sub {1}, fallback => 1 ); __PACKAGE__->mk_attrs(qw( attributes )); __PACKAGE__->mk_attr_accessors(qw( id )); has type => ( is => 'rw', traits => ['Chained'] ); has filename => ( is => 'rw', traits => ['Chained'] ); has is_field => ( is => 'rw', traits => ['Chained'] ); has is_block => ( is => 'rw', traits => ['Chained'] ); has is_repeatable => ( is => 'rw', traits => ['Chained'] ); __PACKAGE__->mk_inherited_accessors( qw( tt_args render_method config_file_path ) ); __PACKAGE__->mk_inherited_merging_accessors(qw( config_callback )); after BUILD => sub { my ( $self, $args ) = @_; # TODO move to attribute 'default' $self->attributes({}); $self->stash({}); return; }; sub name { my ( $self, $name ) = @_; if ( @_ > 1 ) { if ( $name =~ /[\.\[\]]/ ) { croak <<'ERROR_MESSAGE'; element names may not contain periods or square brackets see documentation on nested_names() for details ERROR_MESSAGE } $self->{name} = $name; return $self; } return $self->{name}; } sub setup { } sub get_elements { [] } sub get_element { } sub get_all_elements { [] } sub get_all_element { } sub get_fields { [] } sub get_field { } sub get_deflators { [] } sub get_filters { [] } sub get_constraints { [] } sub get_inflators { [] } sub get_validators { [] } sub get_transformers { [] } sub get_errors { [] } sub clear_errors { } sub pre_process { } sub process { } sub post_process { } sub prepare_id { } sub prepare_attrs { } sub get_output_processors { my $self = shift; return $self->form->get_output_processors(@_); } sub get_output_processor { my $self = shift; return $self->form->get_output_processor(@_); } sub clone { my ($self) = @_; my %new = %$self; $new{tt_args} = Clone::clone( $self->{tt_args} ) if $self->{tt_args}; $new{attributes} = Clone::clone( $self->attributes ); $new{model_config} = Clone::clone( $self->model_config ); return bless \%new, ref $self; } sub render_data { return shift->render_data_non_recursive(@_); } sub render_data_non_recursive { my ( $self, $args ) = @_; my %render = ( name => xml_escape( $self->name ), attributes => xml_escape( $self->attributes ), type => $self->type, filename => $self->filename, is_field => $self->is_field, stash => $self->stash, parent => $self->parent, form => sub { return shift->{parent}->form }, object => $self, $args ? %$args : (), ); weaken( $render{parent} ); $self->prepare_id( \%render ); $self->prepare_attrs( \%render ); return \%render; } __PACKAGE__->meta->make_immutable; 1; __END__ =head1 NAME HTML::FormFu::Element - Element Base Class =head1 SYNOPSIS --- elements: - type: Text name: username constraints: - type: Required - type: Password name: password constraints: - type: Required - type: Equal others: repeat-password - type: Password name: repeat-password - type: Submit =head1 DESCRIPTION Elements are the basic building block of all forms. Elements may be logical form-fields, blocks such as C