################################################################################
# 名      称 ：LoggingDecorator.pm                                             #
# 機      能 ：様々なクラスに対してlogging処理を追加するクラス。               #
# 備      考 ：mod_perl対応。                                                  #
# 作成年月日 ：2003.10.13                                                      #
# 作  成  者 ：Dr.K                                                            #
# Copy Right ：Dr.K                                                            #
################################################################################
package Drk::LoggingDecorator;

use vars qw($VERSION);
$VERSION = "1.00";

use strict;
our $AUTOLOAD;

###--------------------------------------------------------------------------###
#	Method		: new					[public]
#	SUPER Class	: --  
#	Module Call : --
#	機能概要	: コンストラクタ。
#
#	IN1: REF Class
#
#	OUT: 正常:REF Drk::LoggingDecorator
#		 異常:undef
#
#	Ex.. 
#		my $LoggingDecorator = Drk::LoggingDecorator( DBI->new );
#
###--------------------------------------------------------------------------###
	sub new {
        my $class		= shift;
		my $component	= shift;

		bless {
			COMPONENT	=> $component,				## 本来のオブジェクト
			STATEMENT	=> undef,					## 実行したstatement
		}, $class;
	}


###--------------------------------------------------------------------------###
#	Method		: DESTROY				[private]
#	SUPER Class	: DBI
#	Module Call	: --
#	機能概要	: デストラクタ。
#
#	IN1: --
#
#	OUT: --
#
#	Ex.. 
#
###--------------------------------------------------------------------------###
	sub DESTROY {
		my $self = shift;
	}


###--------------------------------------------------------------------------###
#	Method		: get_component			[public]
#	SUPER Class	: --
#	Module Call	: --
#	機能概要	: Decoratorパターン適用前の本来のオブジェクトを取得する
#
#	IN1: --
#
#	OUT: REF Class
#
#	Ex.. 
#		$obj = $self->get_component;
#
###--------------------------------------------------------------------------###
	sub get_component {
		my $self = shift;
		$self->{COMPONENT};
	}


###--------------------------------------------------------------------------###
#	Method		: AUTOLOAD				[private]
#	SUPER Class	: --
#	Module Call	: --
#	機能概要	: AUTOLOADメソッド経由で、未定義メソッドを呼びだし、本来呼び
#				  だそうとしていたメソッドを$AUTOLOAD変数から参照する。取得した
#				  本来のメソッドを実行してエラー監視を行い、エラーの場合ロギング
#				  処理をおこなう。
#
#	IN*: 本来のメソッドの入力に準ずる
#
#	OUT: 本来のメソッドの出力に準ずる
#
#	Ex.. 
#
###--------------------------------------------------------------------------###
	sub AUTOLOAD {
		my $self	= shift;
		my @args	= @_;

		## 本来のメソッド名を取得する
		my $method	= $AUTOLOAD;
		$method =~ s/.+://;
		return if( $method eq 'DESTROY' );

		## 本来のメソッドをログ用に一時保存
		$self->{STATEMENT} = sprintf "%s(%s)", $method, join(', ', @args);

		## 本来のメソッドを実行して結果を格納する。
		$self->get_component->$method(@_);
	}


###--------------------------------------------------------------------------###
#	Method		: statement				[public]
#	SUPER Class	: DBI
#	Module Call : --
#	機能概要	: 直前実行のSTATEMENTを取得する
#
#	IN1: --
#
#	OUT: SCALAR STATEMENT文字列
#
#	Ex.. 
#		my $stmt = $LoggingDecorator->statement
#
###--------------------------------------------------------------------------###
	sub statement {
		my $self = shift;
		return $self->{STATEMENT};
	}



1;
__END__
