OpenInteract2::Error - Simple property object that knows how to un/serialize from/to a file
# create a new error message my $error = OpenInteract2::Error->new( message => "An error happened!", class => 'OpenInteract2::Foo', line => 444, ); # pass to storage class to save to automatic location my $storage = OpenInteract2::ErrorStorage->new(); $storage->save( $error ); # specify location to store error $error->save( '/path/to/error-foo.txt' );
This is a simple property object that can store itself to a file and populate itself from a file.
Generally you won't work with this directly. It will get created automatically when you log an error message or higher with log4perl. For instance:
package My::Class; use Log::Log4perl qw( get_logger ); my $log = get_logger(); sub do_foo { my ( $self ) = @_; unless ( $self->check_foo ) { $log->error( "Check for 'foo' failed -- cannot do the do" ); } }
This will trigger our custom log4perl appender (OpenInteract2::Log::OIAppender) which will create a new error object, populate it with information from the logger and current request, then send it to OpenInteract2::ErrorStorage. The storage class takes care of organizing the errors in the filesystem and passes a valid file for the error object to use in its save() method.
save()
new( %params )
Creates a new object seeded with data from %params. We only set data for which we have known properties -- see below.
%params
If you pass in a valid file for parameter 'file_storage' we retrieve the error's information from the file specified there and populate a new object with it.
save( $file )
Stores the error object in $file. Throws an exception if $file already exists or if we cannot write to it.
$file
This method will create all necessary directories to store $file properly.
Returns: $file if object stored properly.
time
DateTime object representing when error was raised.
message
Error message
category
Typically one of the log4perl categories like 'OI2.ACTION'. Can be set to an arbitrary value though.
class
Class where the error was raised.
line
Line number in which the error was raised.
These properties are generally populated only when there's an active request.
url
URL requested.
host
IP address or hostname of requester.
user_id
ID of user making the request.
username
Name of user making the request.
session
Session ID associated with request.
browser
User-agent string.
referer
String from referer header
OpenInteract2::ErrorStorage
OpenInteract2::Log::OIAppender
Copyright (c) 2005 Chris Winters. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Chris Winters <chris@cwinters.com>
To install OpenInteract2::URL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm OpenInteract2::URL
CPAN shell
perl -MCPAN -e shell install OpenInteract2::URL
For more information on module installation, please visit the detailed CPAN module installation guide.