Utils.pm 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # ABSTRACT: Utilities for the testrail commandline functions.
  2. # PODNAME: TestRail::Utils
  3. package TestRail::Utils;
  4. =head1 DESCRIPTION
  5. Utilities for the testrail commandline functions.
  6. =cut
  7. =head1 FUNCTIONS
  8. =head2 userInput
  9. Wait for user input and return it.
  10. =cut
  11. sub userInput {
  12. local $| = 1;
  13. my $rt = <STDIN>;
  14. chomp $rt;
  15. return $rt;
  16. }
  17. =head2 parseConfig($homedir)
  18. Parse .testrailrc in the provided homedir.
  19. Returns:
  20. ARRAY - (apiurl,password,user)
  21. =cut
  22. sub parseConfig {
  23. my $homedir = shift;
  24. my $results = {};
  25. my $arr =[];
  26. open(my $fh, '<', $homedir . '/.testrailrc') or return (undef,undef,undef);#couldn't open!
  27. while (<$fh>) {
  28. chomp;
  29. @$arr = split(/=/,$_);
  30. if (scalar(@$arr) != 2) {
  31. warn("Could not parse $_ in tlreport config\n");
  32. next;
  33. }
  34. $results->{lc($arr->[0])} = $arr->[1];
  35. }
  36. close($fh);
  37. return ($results->{'apiurl'},$results->{'password'},$results->{'user'});
  38. }
  39. 1;
  40. __END__
  41. =head1 SPECIAL THANKS
  42. Thanks to cPanel Inc, for graciously funding the creation of this module.