[Bps-public-commit] r18321 - in Net-Google-Code/branches/write: .

sunnavy at bestpractical.com sunnavy at bestpractical.com
Tue Feb 10 07:46:34 EST 2009


Author: sunnavy
Date: Tue Feb 10 07:46:29 2009
New Revision: 18321

Modified:
   Net-Google-Code/branches/write/   (props changed)
   Net-Google-Code/branches/write/lib/Net/Google/Code/Issue.pm

Log:
 r19750 at sunnavys-mb:  sunnavy | 2009-02-10 20:35:47 +0800
 refactor a bit, split the labels transform to a method


Modified: Net-Google-Code/branches/write/lib/Net/Google/Code/Issue.pm
==============================================================================
--- Net-Google-Code/branches/write/lib/Net/Google/Code/Issue.pm	(original)
+++ Net-Google-Code/branches/write/lib/Net/Google/Code/Issue.pm	Tue Feb 10 07:46:29 2009
@@ -147,10 +147,8 @@
         }
     );
 
-    # convert hash to array. e.g. Type => Defect to Type-Defect
-    if ( $args{labels} && ref $args{labels} eq 'HASH' ) {
-        $args{labels} =
-          [ map { $_ . '-' . $args{labels}{$_} } keys %{ $args{labels} } ];
+    if ( ref $args{labels} eq 'HASH' ) {
+        $args{labels} = [ $self->labels_array( labels => $args{labels} ) ];
     }
 
     $self->sign_in;
@@ -203,10 +201,8 @@
         }
     );
 
-    # convert hash to array. e.g. Type => Defect to Type-Defect
-    if ( $args{labels} && ref $args{labels} eq 'HASH' ) {
-        $args{labels} =
-          [ map { $_ . '-' . $args{labels}{$_} } keys %{ $args{labels} } ];
+    if ( ref $args{labels} eq 'HASH' ) {
+        $args{labels} = [ $self->labels_array( labels => $args{labels} ) ];
     }
 
     $self->sign_in;
@@ -247,6 +243,18 @@
     }
 }
 
+
+sub labels_array {
+    my $self = shift;
+    my %args = validate( @_, { labels => { type => HASHREF, optional => 1 } } );
+    my $labels = $args{labels} || $self->labels;
+
+    if ( keys %$labels ) {
+        return map { $_ . '-' . $labels->{$_} } keys %$labels;
+    }
+    return;
+}
+
 no Moose;
 __PACKAGE__->meta->make_immutable;
 
@@ -299,6 +307,13 @@
 
 Caveat: 'files' field doesn't work right now, please don't use it.
 
+=head2 labels_array
+convert hashref to array.
+accept labels as arg, e.g. lables_array( labels => { label_hash } )
+if there is no labels arg, use the $self->labels
+
+e.g. { Type => 'Defect', Priority => 'High' } to ( 'Type-Defect', 'Priority-High' )
+
 =head1 AUTHOR
 
 sunnavy  C<< <sunnavy at bestpractical.com> >>



More information about the Bps-public-commit mailing list