Output.pm 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #
  2. # Software Index, Copyright 2010, Software Index Project Team
  3. # Link: http://swi.sourceforge.net
  4. #
  5. # This file is part of Software Index Tool.
  6. #
  7. # Software Index is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, version 3 of the License.
  10. #
  11. # Software Index is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Software Index. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. package Internal::Output;
  20. use strict;
  21. require Exporter;
  22. use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $PREFERRED_PARSER);
  23. @ISA = qw(Exporter);
  24. @EXPORT = qw(DEBUG_ENABLED DEBUG STATUS PRINT);
  25. @EXPORT_OK = qw(DEBUG_ENABLED DEBUG STATUS PRINT);
  26. $VERSION = '1.0';
  27. $PREFERRED_PARSER = undef;
  28. #
  29. # Global variables
  30. #
  31. my $globalDebugEnabled = 0;
  32. #
  33. # Interfaces to get/set internal variables
  34. #
  35. sub DEBUG_ENABLED
  36. {
  37. if (@_)
  38. {
  39. $globalDebugEnabled = shift();
  40. }
  41. return $globalDebugEnabled;
  42. }
  43. #
  44. # Interfaces to dump/print/publish the information
  45. #
  46. sub DEBUG
  47. {
  48. my $text = shift();
  49. if ( $globalDebugEnabled != 0 )
  50. {
  51. print "[SWI DEBUG MESSAGE]: $text\n";
  52. }
  53. }
  54. sub STATUS
  55. {
  56. my $text = shift();
  57. print "[SWI STATUS MESSAGE]: $text\n";
  58. }
  59. sub PRINT
  60. {
  61. my $file = shift();
  62. my $line = shift();
  63. my $severity = shift();
  64. my $text = shift();
  65. $severity = lc $severity;
  66. if ( $severity ne 'debug' || $globalDebugEnabled != 0 )
  67. {
  68. if ($severity eq 'debug')
  69. {
  70. print STDOUT "$file:$line: $severity: $text\n";
  71. }
  72. elsif($severity eq 'error' || $severity eq 'warning' || $severity eq 'notice' || $severity eq 'info')
  73. {
  74. print STDERR "$file:$line: $severity: $text\n";
  75. }
  76. }
  77. }
  78. return 1;