[Rt-commit] r16494 - rt/branches/3.999-DANGEROUS/lib/RT

ruz at bestpractical.com ruz at bestpractical.com
Wed Oct 22 05:03:00 EDT 2008


Author: ruz
Date: Wed Oct 22 05:02:50 2008
New Revision: 16494

Modified:
   rt/branches/3.999-DANGEROUS/lib/RT/StatusSchema.pm

Log:
* improve status schema API a little bit
** valid and is_valid can now take optional array of types

Modified: rt/branches/3.999-DANGEROUS/lib/RT/StatusSchema.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/StatusSchema.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/StatusSchema.pm	Wed Oct 22 05:02:50 2008
@@ -122,13 +122,23 @@
 Statuses are not sorted alphabetically, instead initial goes first,
 then active and then inactive.
 
+Takes optional list of status types, from 'initial', 'active' or
+'inactive'. For example:
+
+    $schema->valid('initial', 'active');
+
 =cut
 
 sub valid {
     my $self = shift;
-    my $type = shift;
-
-    return @{ $self->{'data'}{ $type || '' } || [] };
+    my @types = @_;
+    unless ( @types ) {
+        return @{ $self->{'data'}{''} || [] };
+    }
+    
+    my @res;
+    push @res, @{ $self->{'data'}{ $_ } || [] } foreach @types;
+    return @res;
 }
 
 =head3 is_valid
@@ -136,12 +146,20 @@
 Takes a status and returns true if value is a valid status for the current
 schema. Otherwise, returns false.
 
+Takes optional list of status types after the status, so it's possible check
+validity in particular sets, for example:
+
+    # returns true if status is valid and from initial or active set
+    $schema->is_valid('some_status', 'initial', 'active');
+
+See also </valid>.
+
 =cut
 
 sub is_valid {
     my $self  = shift;
     my $value = lc shift;
-    return scalar grep lc($_) eq $value, $self->valid;
+    return scalar grep lc($_) eq $value, $self->valid( @_ );
 }
 
 =head3 initial


More information about the Rt-commit mailing list