Template.pm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # This is a template for creating your own logfile parser. After making the
  2. # necessary changes to the template, you will need to add the new module to
  3. # pisg.pl and add an entry for it in the choose_log_format subroutine.
  4. package Pisg::Parser::Format::Template;
  5. use strict;
  6. $^W = 1;
  7. # These three variables are regular expressions for extracting information
  8. # from the logfile. $normalline is for lines where the person merely said
  9. # something, $actionline is for lines where the person performed an action,
  10. # and# $thirdline matches everything else, including things like kicks, nick
  11. # changes, and op grants. See the thirdline subroutine for a list of
  12. # everything it should match.
  13. my $normalline = '';
  14. my $actionline = '';
  15. my $thirdline = '';
  16. my ($debug);
  17. # The $debug subroutine needs to be passed to the module so output will go
  18. # to the correct file.
  19. sub new
  20. {
  21. my $self = shift;
  22. $debug = shift;
  23. return bless {};
  24. }
  25. # Parse a normal line - returns a hash with 'hour', 'nick' and 'saying'
  26. sub normalline
  27. {
  28. my ($self, $line, $lines) = @_;
  29. my %hash;
  30. if ($line =~ /$normalline/) {
  31. $debug->("[$lines] Normal: $1 $2 $3");
  32. # Most log formats are regular enough that you can just match the
  33. # appropriate things with parentheses in the regular expression.
  34. $hash{hour} = $1;
  35. $hash{nick} = $2;
  36. $hash{saying} = $3;
  37. return \%hash;
  38. } else {
  39. return;
  40. }
  41. }
  42. # Parse an action line - returns a hash with 'hour', 'nick' and 'saying'
  43. sub actionline
  44. {
  45. my ($self, $line, $lines) = @_;
  46. my %hash;
  47. if ($line =~ /$actionline/) {
  48. $debug->("[$lines] Action: $1 $2 $3");
  49. # Most log formats are regular enough that you can just match the
  50. # appropriate things with parentheses in the regular expression.
  51. $hash{hour} = $1;
  52. $hash{nick} = $2;
  53. $hash{saying} = $3;
  54. return \%hash;
  55. } else {
  56. return;
  57. }
  58. }
  59. # Parses the 'third' line - (the third line is everything else, like
  60. # topic changes, mode changes, kicks, etc.)
  61. # thirdline() has to return a hash with the following keys, for
  62. # every format:
  63. # hour - the hour we're in (for timestamp logging)
  64. # min - the minute we're in (for timestamp logging)
  65. # nick - the nick
  66. # kicker - the nick which were kicked (if any)
  67. # newtopic - the new topic (if any)
  68. # newmode - deops or ops, must be '+o' or '-o', or '+ooo'
  69. # newjoin - a new nick which has joined the channel
  70. # newnick - a person has changed nick and this is the new nick
  71. #
  72. # The hash may also have a "repeated" key indicating the number of times
  73. # the line was repeated.
  74. sub thirdline
  75. {
  76. my ($self, $line, $lines) = @_;
  77. my %hash;
  78. if ($line =~ /$thirdline/) {
  79. $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8 $9");
  80. $hash{hour} = $1;
  81. $hash{min} = $2;
  82. $hash{nick} = $3;
  83. # Format-specific stuff goes here.
  84. return \%hash;
  85. } else {
  86. return;
  87. }
  88. }
  89. 1;