PageRenderTime 36ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/libs/perl/Choicetool/Base/Debug.pm

#
Perl | 81 lines | 43 code | 16 blank | 22 comment | 4 complexity | 47534c176bb190c9cd1f2caabe181954 MD5 | raw file
Possible License(s): GPL-2.0
  1. # -*- perl -*-
  2. #
  3. # Debug.pm
  4. #
  5. # Copyright (C) 2008, 2009 Francesco Salvestrini
  6. #
  7. # This program 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; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. #
  21. package Choicetool::Base::Debug;
  22. use 5.8.0;
  23. use warnings;
  24. use strict;
  25. use diagnostics;
  26. use Carp;
  27. #use POSIX qw(&exit EXIT_FAILURE EXIT_SUCCESS);
  28. use Choicetool::Autoconfig;
  29. BEGIN {
  30. use Exporter ();
  31. our ($VERSION, @ISA, @EXPORT);
  32. @ISA = qw(Exporter);
  33. @EXPORT = qw(&bug
  34. &assert
  35. &missing);
  36. }
  37. sub bug ($)
  38. {
  39. my $string = shift;
  40. print STDERR "\n";
  41. if (defined($string)) {
  42. print STDERR "Bug hit: " . $string . "\n";
  43. } else {
  44. print STDERR "Bug hit\n";
  45. }
  46. print STDERR
  47. "Please report the problem to " .
  48. "<" . $Choicetool::Autoconfig::PACKAGE_BUGREPORT . ">\n";
  49. print STDERR "\n";
  50. confess(); # From Carp module
  51. # We must exit with a different exit code that a generic error (which is 1)
  52. exit 88;
  53. }
  54. sub assert ($)
  55. {
  56. my $expression = shift;
  57. if ($expression == 0) {
  58. bug("Assertion failed !!!");
  59. }
  60. }
  61. sub missing ()
  62. {
  63. bug("Missing code");
  64. }
  65. 1;