Log::NullLogLite - The C<Log::NullLogLite> class implements the Null Object


Log-LogLite documentation Contained in the Log-LogLite distribution.

Index


Code Index:

NAME

Top

Log::NullLogLite - The Log::NullLogLite class implements the Null Object pattern for the Log::LogLite class.

SYNOPSIS

Top

  use Log::NullLogLite;

  # create new Log::NullLogLite object
  my $log = new Log::NullLogLite();

  ...

  # we had an error (this entry will not be written to the log 
  # file because we use Log::NullLogLite object).
  $log->write("Could not open the file ".$file_name.": $!", 4);

DESCRIPTION

Top

The Log::NullLogLite class is derived from the Log::LogLite class and implement the Null Object Pattern to let us to use the Log::LogLite class with null Log::LogLite objects. We might want to do that if we use a Log::LogLite object in our code, and we do not want always to actually define a Log::LogLite object (i.e. not always we want to write to a log file). In such a case we will create a Log::NullLogLite object instead of the Log::LogLite object, and will use that object instead. The object has all the methods that the Log::LogLite object has, but those methods do nothing. Thus our code will continue to run without any change, yet we will not have to define a log file path for the Log::LogLite object, and no log will be created.

CONSTRUCTOR

Top

new ( FILEPATH [,LEVEL [,DEFAULT_MESSAGE ]] )

The constructor. The parameters will not have any affect. Returns the new Log::NullLogLite object.

METHODS

Top

write( MESSAGE [, LEVEL ] )

Does nothing. The parameters will not have any affect. Returns nothing.

level( [ LEVEL ] )

Does nothing. The parameters will not have any affect. Returns -1.

default_message( [ MESSAGE ] )

Does nothing. The parameters will not have any affect. Returns empty string ("").

AUTHOR

Top

Rani Pinchuk, rani@cpan.org

COPYRIGHT

Top

SEE ALSO

Top

Log::LogLite(3), The Null Object Pattern - Bobby Woolf - PLoP96 - published in Pattern Languages of Program Design 3 (http://cseng.aw.com/book/0,,0201310112,00.html)


Log-LogLite documentation Contained in the Log-LogLite distribution.

package Log::NullLogLite;

use strict;
use vars qw($VERSION @ISA);

$VERSION = 0.82;

# According to the Null pattern.
#
# Log::NullLogLite inherits from Log::LogLite and implement the Null 
# Object Pattern.
use Log::LogLite;
@ISA = ("Log::LogLite");
package Log::NullLogLite;
use strict;

##########################################
# new($filepath)
# new($filepath,$level)
# new($filepath,$level,$default_message)
##########################################
# the constructor
sub new {
    my $proto = shift; # get the class name
    my $class = ref($proto) || $proto;
    my $self  = {};
    bless ($self, $class);
    return $self;
} # of new

########################
# write($message, $level)
########################
# will log the message in the log file only if $level>=LEVEL
sub write {
    my $self = shift;
} # of write   

##########################
# level()
# level($level)
##########################
# an interface to LEVEL
sub level {
    my $self = shift;
    return -1;
} # of level

###########################
# default_message()
# default_message($message)
###########################
# an interface to DEFAULT_MESSAGE
sub default_message {
    my $self = shift;
    return "";
} # of default_message

1;
__END__

############################################################################