Gaim::Log::Finder - Find Gaim's Log Files


Gaim-Log-Parser documentation Contained in the Gaim-Log-Parser distribution.

Index


Code Index:

NAME

Top

Gaim::Log::Finder - Find Gaim's Log Files

SYNOPSIS

Top

    use Gaim::Log::Finder;

    my $finder = Gaim::Log::Finder->new(
        callback => sub { print "Found $_[1]\n"; }
    );

    $finder->find();

DESCRIPTION

Top

Gaim::Log::Finder traverses through all known Gaim log file hierarchies and calls back to the previously defined callback function every time it finds a Gaim log file.

Methods

my $finder = Gaim::Log::Finder-new(callback => $coderef)>

The callback function that gets passed in as a code reference will be called later for every log file found (see below).

The finder will start in the .gaim/logs directory under the current user's home directory. If it finds .purple/logs, which is the log file location for gaim > 2.0 logs, it will use that instead. If, for some reason you want to start at a different location, pass it in as start_dir:

    my $finder = Gaim::Log::Finder->new(
        callback  => sub { print "Found $_[0]\n"; },
        start_dir => "/tmp",
    );

my $finder = $parser->find()

Starts the finder, and will call the previously defined callback function every time it finds a Gaim log file. It will pass the following parameters to the callback function:

    sub gaim_log_callback {
        my($self, $logfile, $protocol, $local_user, 
           $remote_user, $file) = @_;
        # ...
    }

$self is an object reference to the finder itself. $logfile is the full path to the logfile. $protocol is the IM transport mechanism/provider used, this could be yahoo, aim, jabber or similar. $local_user is the local user's userid. $local_user is the user's id who's at the other end of the conversation. $file is the name of the text file.

LEGALESE

Top

Copyright 2007 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Top

2007, Mike Schilli <cpan@perlmeister.com>


Gaim-Log-Parser documentation Contained in the Gaim-Log-Parser distribution.

###########################################
package Gaim::Log::Finder;
###########################################
use strict;
use warnings;
use Log::Log4perl qw(:easy);
use File::Find ();

our $VERSION = "0.02";

###########################################
sub new {
###########################################
    my($class, @options) = @_;

    my ($home) = glob "~";

    my $start_dir;

    for (qw(.purple .gaim)) {
        my $dir = "$home/$_";

        if(-d $dir) {
            $start_dir = "$dir/logs";
            last;
        }
    }

    my $self = {
        start_dir => $start_dir,
        callback  => sub { 1 },
        @options,
    };

    return bless $self, $class;
}

###########################################
sub find {
###########################################
    my($self, $start_dir) = @_;

    $start_dir = $self->{start_dir} unless
        defined $start_dir;

    File::Find::find sub { $self->wanted() },
        $start_dir;
}

###########################################
sub wanted {
###########################################
    my($self) = @_;
    
    return if $File::Find::name =~ m#$self->{start_dir}/(.*?)/(.*?)/.system/#;
    my $path = $File::Find::name;

    my($protocol, $local_user, $remote_user, $file) =
            $path =~ m#$self->{start_dir}/(.*?)/(.*?)/(.*?)/(.*\.txt)$#;

    if(defined $file) {
        $self->{callback}->($self, 
            $File::Find::name,
            $protocol,
            $local_user,
            $remote_user,
            $file
        );
    }
}

1;

__END__