The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Data::Freq::Record - Represents a record added to Data::Freq counting

VERSION

Version 0.02

EXPORT

logsplit

Splits a text that represents a line in a log file.

    use Data::Freq::Record qw(logsplit);
    
    logsplit("12.34.56.78 - user1 [01/Jan/2012:01:02:03 +0000] "GET / HTTP/1.1" 200 44");
    
    # Returns an array with:
    #     [0]: '12.34.56.78'
    #     [1]: '-'
    #     [2]: '[01/Jan/2012:01:02:03 +0000]'
    #     [3]: '"GET / HTTP/1.1"'
    #     [4]: '200'
    #     [5]: '44'

A log line is typically whitespace-separated, while anything inside brackets [...], braces {...}, parentheses (...), double quotes "...", or single quotes '...' is considered as one chunk as a whole even if whitespaces may be included inside.

The logsplit function is intended to split such a log line into an array.

METHODS

new

Usage:

    # Text
    Data::Freq::Record->new("text");
    
    Data::Freq::Record->new("an input line from a log file\n");
        # Line break at the end will be stripped off
    
    # Array ref
    Data::Freq::Record->new(['an', 'array', 'ref']);
    
    # Hash ref
    Data::Freq::Record->new({key => 'hash ref'});

Constructs a record object, which carries an input data in the form of a text, an array ref, or a hash ref. Each form of the input (or a converted value) can be retrieved by the text(), array(), or hash() function.

When an array ref is required via the "array"() method while a text is given as the input, the array ref is created internally by the logsplit() function.

When a text is required via the text() method while an array ref is given as the input, the text is taken from the first element of the array.

The hash form is incompatible with the other forms, and whenever an incompatible form is required, the return value is undef.

If the text input has a line break at the end, it is stripped off. If the line break should not be stripped off, use an array ref with the first element set to the text.

text

Retrieves the text form of the input.

If the input was an array ref, the first element of the array is returned.

array

Retrieves the array ref form of the input.

If the input was a text, it is split by the logsplit() function..

hash

Retrieves the hash ref form of the input.

date

Extracts a date/time from the input and returns the timestamp value.

The date/time is retrieved from the array ref form (or from a split text), where the first element enclosed by a pair of brackets [...] is parsed by the Date::Parse::str2time() function.

AUTHOR

Mahiro Ando, <mahiro at cpan.org>

LICENSE AND COPYRIGHT

Copyright 2012 Mahiro Ando.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.