Changeset 320
- Timestamp:
- 10/25/06 18:04:09 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
library/perl/trunk/HTML-Widget-Kwalify
- Property svn:ignore set to blib
library/perl/trunk/HTML-Widget-Kwalify/lib/HTML/Widget/Kwalify.pm
r319 r320 8 8 9 9 use base qw( HTML::Widget ); 10 use YAML qw( LoadFile Dump DumpFile);10 use YAML qw( LoadFile DumpFile Load Dump ); 11 11 use UNIVERSAL; 12 12 use CGI::Expand; … … 18 18 19 19 unless ( ref $yaml ) { 20 $yaml = LoadFile($yaml); 20 eval { $yaml = Load($yaml); }; 21 $yaml = LoadFile($yaml) if $@; 21 22 } 22 23 … … 56 57 !$class ? 57 58 do { 58 if ( grep { $arg eq $_ } ( qw/ str int any / ) ) {59 if ( grep { $arg eq $_ } ( qw/ str int any date / ) ) { 59 60 $element->type($arg); 60 61 push @elements, $element; … … 70 71 71 72 push @{ $clone->stack }, $key 72 unless ( grep { $key eq $_ } ( qw/ mapping sequence desc name / ));73 if ( isa($arg->{$key}, 'HASH') and defined $arg->{$key}->{type}); 73 74 74 75 if ( $key eq 'sequence' ) { … … 80 81 if ( $key eq 'type' ) { 81 82 push @{ $clone->enum }, @{ $arg->{enum} } if $arg->{enum}; 82 $clone->name($arg->{name}) if $arg->{name}; 83 $clone->desc($arg->{desc}) if $arg->{desc}; 83 for ( qw/ name desc / ) { 84 $clone->$_($arg->{$_}) if $arg->{$_}; 85 } 84 86 } 87 88 if ( defined $arg->{pattern} and $arg->{pattern} =~ m!/(.+)/! ) { 89 $clone->pattern($1); 90 } 91 92 93 if ( defined $arg->{required} 94 and ( $arg->{required} eq 'yes' or $arg->{required} eq 'true' ) ) { 95 $clone->required(1); 96 } 97 85 98 $hash->{$key} = $curry->($clone, [ $arg->{$key} ]); 86 99 } … … 103 116 104 117 for ( @elements ) { 105 pop @{$_->stack};106 118 my $name = join '.', @{$_->stack}; 107 119 my $label = $_->name || $name; … … 119 131 $element->comment($_->desc); 120 132 133 # set constraints 121 134 $self->constraint('Integer', $name) if $_->type eq 'int'; 122 $self->constraint('String', $name) if $_->type eq 'str'; 135 #$self->constraint('String', $name) if $_->type eq 'str'; 136 #$self->constraint('All', $name) if $_->required; 137 138 if ( $_->pattern ) { 139 my $c = $self->constraint('Regex', $name); 140 $c->regex($_->pattern); 141 } 123 142 } 124 143 125 144 return $self; 145 } 146 147 { 148 no warnings 'redefine'; 149 *HTML::Element::_xml_escape = sub { 150 foreach my $x (@_) { 151 $x =~ s!([<&>])!'&#'.(ord($1)).';'!seg; 152 } 153 return; 154 }; 126 155 } 127 156 … … 131 160 use Storable; 132 161 133 __PACKAGE__->mk_accessors( qw/ stack type enum name desc / );162 __PACKAGE__->mk_accessors( qw/ stack type enum name desc pattern required / ); 134 163 135 164 sub new { … … 175 204 } 176 205 177 1; # Magic true value required at end of module206 1; 178 207 __END__ 179 208 … … 292 321 =head1 AUTHOR 293 322 294 Gosuke Miyashita C<< <gosukenator @gmail.com> >>323 Gosuke Miyashita C<< <gosukenator at gmail.com> >> 295 324 296 325 297 326 =head1 LICENCE AND COPYRIGHT 298 327 299 Copyright (c) 2006, Gosuke Miyashita C<< <gosukenator @gmail.com> >>. All rights reserved.328 Copyright (c) 2006, Gosuke Miyashita C<< <gosukenator at gmail.com> >>. All rights reserved. 300 329 301 330 This module is free software; you can redistribute it and/or
