override BUILDARGS instead of new
This commit is contained in:
parent
381e1ff022
commit
a725942c17
5 changed files with 21 additions and 16 deletions
|
|
@ -56,10 +56,10 @@ other possible value is "application/x-www-form-urlencoded".
|
|||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
sub BUILDARGS {
|
||||
my ( $class, $session, %properties ) = @_;
|
||||
$properties{ session } = $session;
|
||||
return $class->SUPER::new( %properties );
|
||||
return \%properties;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -59,11 +59,11 @@ Optional. A synonym for C<label>.
|
|||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
sub BUILDARGS {
|
||||
my ( $class, $session, %properties ) = @_;
|
||||
$properties{ session } = $session;
|
||||
$properties{ label } ||= delete $properties{ legend };
|
||||
return $class->SUPER::new( %properties );
|
||||
return \%properties;
|
||||
}
|
||||
|
||||
sub getFooter {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package WebGUI::FormBuilder::Role::HasFields;
|
|||
|
||||
use strict;
|
||||
use Moose::Role;
|
||||
use Try::Tiny;
|
||||
|
||||
requires 'session', 'pack', 'unpack';
|
||||
|
||||
|
|
@ -47,14 +48,18 @@ sub addField {
|
|||
}
|
||||
else {
|
||||
# Is $type a class name?
|
||||
eval { WebGUI::Pluggable::load( $type ) };
|
||||
if ( $@ ) {
|
||||
eval { WebGUI::Pluggable::load( "WebGUI::Form::" . ucfirst( $type ) ) };
|
||||
if ( $@ ) {
|
||||
$self->session->error("Could not load field type '$type'. Try loading it manually." );
|
||||
confess "Could not load field type '$type'. Try loading it manually.";
|
||||
}
|
||||
$type = "WebGUI::Form::" . ucfirst( $type );
|
||||
my $file = $type;
|
||||
$file =~ s{::}{/}g;
|
||||
$file .= ".pm";
|
||||
|
||||
# Load the class
|
||||
# Try to load the WebGUI Field first in case we conveniently overlap with a common name
|
||||
# (like Readonly)
|
||||
if ( $INC{'WebGUI/Form/'.$file} || try { require 'WebGUI/Form/' . $file } ) {
|
||||
$type = 'WebGUI::Form::' . $type;
|
||||
}
|
||||
elsif ( !$INC{$file} && !try { require $file; } ) {
|
||||
confess sprintf "Could not load form control class %s", $type;
|
||||
}
|
||||
$field = $type->new( $self->session, { @properties } );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,10 +53,10 @@ Optional. A label for the tab.
|
|||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
sub BUILDARGS {
|
||||
my ( $class, $session, %properties ) = @_;
|
||||
$properties{ session } = $session;
|
||||
return $class->SUPER::new( %properties );
|
||||
return \%properties;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -43,10 +43,10 @@ The name of the tabset. Required.
|
|||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
sub BUILDARGS {
|
||||
my ( $class, $session, %properties ) = @_;
|
||||
$properties{ session } = $session;
|
||||
return $class->SUPER::new( %properties );
|
||||
return \%properties;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue