add toTemplateVars method to form controls
This commit is contained in:
parent
2c51e6d4fd
commit
ca42a0544d
2 changed files with 35 additions and 5 deletions
|
|
@ -302,9 +302,10 @@ sub generateIdParameter {
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 get ( var )
|
=head2 get ( [var] )
|
||||||
|
|
||||||
Returns a property of this form object.
|
Returns a property of this form object. If no property is specified, returns a hashref of all
|
||||||
|
properties.
|
||||||
|
|
||||||
=head3 var
|
=head3 var
|
||||||
|
|
||||||
|
|
@ -315,7 +316,11 @@ The variable name of the value to return.
|
||||||
sub get {
|
sub get {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $var = shift;
|
my $var = shift;
|
||||||
return $self->{_params}{$var};
|
if ( $var ) {
|
||||||
|
return $self->{_params}{$var};
|
||||||
|
}
|
||||||
|
|
||||||
|
return $self->{_params};
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -696,7 +701,20 @@ sub toHtmlWithWrapper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 toTemplateVars ( )
|
||||||
|
|
||||||
|
Returns a hashref of template variables of the properties of this control, used
|
||||||
|
to re-create it in a template.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub toTemplateVars {
|
||||||
|
my ( $self ) = @_;
|
||||||
|
my %var = %{$self->get};
|
||||||
|
return \%var;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ sub t_00_method_check : Test(1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub t_01_get_set : Test(2) {
|
sub t_01_get_set : Test(3) {
|
||||||
my $test = shift;
|
my $test = shift;
|
||||||
my $session = $test->session;
|
my $session = $test->session;
|
||||||
|
|
||||||
|
|
@ -49,7 +49,7 @@ sub t_01_get_set : Test(2) {
|
||||||
|
|
||||||
lives_ok { $form->set('name', 'form1'); } 'set name';
|
lives_ok { $form->set('name', 'form1'); } 'set name';
|
||||||
is $form->get('name'), 'form1', 'get name';
|
is $form->get('name'), 'form1', 'get name';
|
||||||
|
cmp_deeply $form->get, superhashof({ name => 'form1' }), 'get hashref';
|
||||||
}
|
}
|
||||||
|
|
||||||
sub t_02_instanced : Test(1) {
|
sub t_02_instanced : Test(1) {
|
||||||
|
|
@ -63,4 +63,16 @@ sub t_02_instanced : Test(1) {
|
||||||
is $form->get('name'), 'form1', 'name set on instanciation';
|
is $form->get('name'), 'form1', 'name set on instanciation';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub t_03_toTemplateVars : Test(2) {
|
||||||
|
my $test = shift;
|
||||||
|
my $session = $test->session;
|
||||||
|
|
||||||
|
my $form = $test->class->new($session, {
|
||||||
|
name => 'form1',
|
||||||
|
});
|
||||||
|
|
||||||
|
cmp_deeply $form->get, superhashof({ name => 'form1' }), 'toTemplateVars hashref';
|
||||||
|
isnt $form->toTemplateVars, $form->get, 'toTemplateVars creates safe hashref';
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue