[Bps-public-commit] r17505 - in Net-Trac/trunk: .
trs at bestpractical.com
trs at bestpractical.com
Wed Dec 31 23:02:31 EST 2008
Author: trs
Date: Wed Dec 31 23:02:30 2008
New Revision: 17505
Modified:
Net-Trac/trunk/ (props changed)
Net-Trac/trunk/Makefile.PL
Net-Trac/trunk/lib/Net/Trac/Ticket.pm
Log:
r43374 at zot: tom | 2008-12-31 23:02:24 -0500
Actually use valid_* to validate fields
Modified: Net-Trac/trunk/Makefile.PL
==============================================================================
--- Net-Trac/trunk/Makefile.PL (original)
+++ Net-Trac/trunk/Makefile.PL Wed Dec 31 23:02:30 2008
@@ -16,6 +16,7 @@
requires 'Params::Validate';
requires 'WWW::Mechanize' => '1.52';
requires 'DateTime::Format::ISO8601';
+requires 'Lingua::EN::Inflect';
auto_install;
sign;
Modified: Net-Trac/trunk/lib/Net/Trac/Ticket.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac/Ticket.pm (original)
+++ Net-Trac/trunk/lib/Net/Trac/Ticket.pm Wed Dec 31 23:02:30 2008
@@ -1,6 +1,7 @@
package Net::Trac::Ticket;
use Moose;
use Params::Validate qw(:all);
+use Lingua::EN::Inflect qw(PL);
use Net::Trac::TicketHistory;
use Net::Trac::TicketAttachment;
@@ -46,7 +47,14 @@
my $content = $self->connection->mech->content;
my $stateref = $self->connection->_csv_to_struct( data => \$content, key => 'id' );
return undef unless $stateref;
- return $self->load_from_hashref( $stateref->{$id} );
+
+ my $tid = $self->load_from_hashref( $stateref->{$id} );
+
+ # Load metadata up for create and update
+ $self->_fetch_new_ticket_metadata;
+ $self->_fetch_update_ticket_metadata;
+
+ return $tid;
}
sub load_from_hashref {
@@ -95,7 +103,7 @@
[ $form->find_input("field_priority")->possible_values ] );
my $severity = $form->find_input("field_severity");
- $self->valid_severities( $severity->possible_values ) if $severity;
+ $self->valid_severities( [$severity->possible_values] ) if $severity;
# my @inputs = $form->inputs;
#
@@ -113,16 +121,37 @@
return undef unless $form;
my $resolutions = $form->find_input("action_resolve_resolve_resolution");
- $self->valid_resolutions( $resolutions->possible_values ) if $resolutions;
+ $self->valid_resolutions( [$resolutions->possible_values] ) if $resolutions;
return 1;
}
+sub _validation_rules {
+ my $self = shift;
+ my %rules;
+ for my $prop ( @_ ) {
+ my $method = "valid_" . PL($prop);
+ if ( $self->can($method) ) {
+ my $values = join '|', map { $_ } grep { defined and length } @{$self->$method};
+ if ( length $values ) {
+ my $check = qr{^(?:$values)$}i;
+ $rules{$prop} = { type => SCALAR, regex => $check, optional => 1 };
+ } else {
+ $rules{$prop} = 0;
+ }
+ }
+ else {
+ $rules{$prop} = 0; # optional
+ }
+ }
+ return \%rules;
+}
+
sub create {
my $self = shift;
my %args = validate(
@_,
- { map { $_ => 0 } grep { !/resolution/ } $self->valid_props }
+ $self->_validation_rules( grep { !/resolution/ } $self->valid_props )
);
my ($form,$form_num) = $self->_get_new_ticket_form();
@@ -153,7 +182,7 @@
{
comment => 0,
no_auto_status => { default => 0 },
- map { $_ => 0 } $self->valid_props
+ %{$self->_validation_rules( $self->valid_props )}
}
);
More information about the Bps-public-commit
mailing list