]> git.donarmstrong.com Git - debbugs.git/commitdiff
* use Params::validate in read_log_records
authorDon Armstrong <don@donarmstrong.com>
Sat, 9 Aug 2008 18:35:33 +0000 (11:35 -0700)
committerDon Armstrong <don@donarmstrong.com>
Sat, 9 Aug 2008 18:35:33 +0000 (11:35 -0700)
 * logfh is a HANDLE, not a SCALAR

Debbugs/Log.pm

index c4d741e6ab46f322a9519075c2d60cbba416de64..5e7635147470ffc7137454fa4906d8ddc981618c 100644 (file)
@@ -169,7 +169,7 @@ sub new
                                spec   => {bug_num => {type => SCALAR,
                                                       optional => 1,
                                                      },
-                                          logfh   => {type => SCALAR,
+                                          logfh   => {type => HANDLE,
                                                       optional => 1,
                                                      },
                                           log_name => {type => SCALAR,
@@ -299,14 +299,36 @@ Takes a .log filehandle as input, and returns an array of all records in
 that file. Throws exceptions using die(), so you may want to wrap this in an
 eval().
 
+Uses exactly the same options as Debbugs::Log::new
+
 =cut
 
-sub read_log_records (*)
+sub read_log_records
 {
-    my $logfh = shift;
+    my %param;
+    if (@_ == 1) {
+        ($param{logfh}) = @_;
+    }
+    else {
+        %param = validate_with(params => \@_,
+                               spec   => {bug_num => {type => SCALAR,
+                                                      optional => 1,
+                                                     },
+                                          logfh   => {type => HANDLE,
+                                                      optional => 1,
+                                                     },
+                                          log_name => {type => SCALAR,
+                                                       optional => 1,
+                                                      },
+                                         }
+                              );
+    }
+    if (grep({exists $param{$_} and defined $param{$_}} qw(bug_num logfh log_name)) ne 1) {
+        croak "Exactly one of bug_num, logfh, or log_name must be passed and must be defined";
+    }
 
     my @records;
-    my $reader = Debbugs::Log->new($logfh);
+    my $reader = Debbugs::Log->new(%param);
     while (defined(my $record = $reader->read_record())) {
        push @records, $record;
     }