Skip to content

Commit

Permalink
r27906@minion101: rjbs | 2006-11-13 10:40:14 -0500
Browse files Browse the repository at this point in the history
 critic
  • Loading branch information
rjbs committed Nov 13, 2006
1 parent dcba44f commit 72378ac
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 54 deletions.
1 change: 0 additions & 1 deletion MANIFEST
Expand Up @@ -11,6 +11,5 @@ t/parse_line.t
t/pod.t
t/pod-coverage.t
t/samples/sample01.log
META.yml Module meta-data (added by MakeMaker)
t/perl-critic.t
LICENSE
100 changes: 50 additions & 50 deletions lib/Parse/IRCLog.pm
Expand Up @@ -24,16 +24,16 @@ our $VERSION = '1.101';

=head1 SYNOPSIS
use Parse::IRCLog;
use Parse::IRCLog;
$result = Parse::IRCLog->parse("perl-2004-02-01.log");
$result = Parse::IRCLog->parse("perl-2004-02-01.log");
my %to_print = ( msg => 1, action => 1 );
my %to_print = ( msg => 1, action => 1 );
for ($result->events) {
next unless $to_print{ $_->{type} };
print "$_->{nick}: $_->{text}\n";
}
for ($result->events) {
next unless $to_print{ $_->{type} };
print "$_->{nick}: $_->{text}\n";
}
=head1 DESCRIPTION
Expand Down Expand Up @@ -131,42 +131,42 @@ sub patterns {
$p->{chan} = qr/((?:&|#)[\w\[\]\{\}\(\)&#^]*)/;

$p->{nick_container} = qr/
<
\s*
([%@])?
\s*
$p->{nick}
(?:
:
$p->{chan}
)?
\s*
>
<
\s*
([%@])?
\s*
$p->{nick}
(?:
:
$p->{chan}
)?
\s*
>
/x;

$p->{timestamp} = qr/\[?(\d\d:\d\d(?::\d\d)?)?\]?/;

$p->{action_leader} = qr/\*/;

$p->{msg} = qr/
$p->{timestamp}
\s*
$p->{nick_container}
\s+
(.+)
/x;

$p->{action} = qr/
$p->{timestamp}
\s*
$p->{action_leader}
\s+
([%@])?
\s*
$p->{nick}
\s
(.+)
/x;
$p->{msg} = qr/
$p->{timestamp}
\s*
$p->{nick_container}
\s+
(.+)
/x;

$p->{action} = qr/
$p->{timestamp}
\s*
$p->{action_leader}
\s+
([%@])?
\s*
$p->{nick}
\s
(.+)
/x;

$p;
}
Expand All @@ -185,11 +185,11 @@ sub parse {
$self = $self->new unless ref $self;

my $symbol = Symbol::gensym;
open $symbol, "<", $_[0] or die "couldn't open $_[0]: $!";
open $symbol, "<", $_[0] or Carp::croak "couldn't open $_[0]: $!";

my @events;
push @events, $self->parse_line($_) while (<$symbol>);
Parse::IRCLog::Result->new(@events);
my @events;
push @events, $self->parse_line($_) while (<$symbol>);
Parse::IRCLog::Result->new(@events);
}

=item C<< parse_line($line) >>
Expand All @@ -204,14 +204,14 @@ If no match can be found, an "unknown" event is returned.
=cut

sub parse_line {
my ($self, $line) = @_;
if ($line) {
return { type => 'msg', timestamp => $1, nick_prefix => $2, nick => $3, text => $5 }
if $line =~ $self->patterns->{msg};
return { type => 'action', timestamp => $1, nick_prefix => $2, nick => $3, text => $4 }
if $line =~ $self->patterns->{action};
}
return { type => 'unknown', text => $line };
my ($self, $line) = @_;
if ($line) {
return { type => 'msg', timestamp => $1, nick_prefix => $2, nick => $3, text => $5 }
if $line =~ $self->patterns->{msg};
return { type => 'action', timestamp => $1, nick_prefix => $2, nick => $3, text => $4 }
if $line =~ $self->patterns->{action};
}
return { type => 'unknown', text => $line };
}

=back
Expand All @@ -227,7 +227,7 @@ only one or two patterns. For example, to use the default C<nick> pattern but
override the C<nick_container> or C<action_leader>. This sounds like a very
good idea, actually, now that I write it down.
=head1 AUTHORS
=head1 AUTHOR
Ricardo SIGNES E<lt>rjbs@cpan.orgE<gt>
Expand Down
14 changes: 11 additions & 3 deletions lib/Parse/IRCLog/Result.pm
Expand Up @@ -4,12 +4,20 @@ package Parse::IRCLog::Result;
use strict;
use warnings;

our $VERSION = sprintf "%d.%03d", q$Revision: 1.2 $ =~ /(\d+)/g;

=head1 NAME
Parse::IRCLog::Result -- results of parsing an IRC logfile
=head1 VERSION
version 1.101
$Id$
=cut

our $VERSION = '1.101';

=head1 SYNOPSIS
use Parse::IRCLog;
Expand Down Expand Up @@ -66,7 +74,7 @@ Provide iterator functionality. Five minutes of looking didn't find a mixin
class for iterators, so I might end up just delegating iterator methods to a
tied array object or something. This can wait.
=head1 AUTHORS
=head1 AUTHOR
Ricardo SIGNES E<lt>rjbs@cpan.orgE<gt>
Expand Down

0 comments on commit 72378ac

Please sign in to comment.