Tripletail

 view release on metacpan or  search on metacpan

lib/Tripletail/Debug.pm  view on Meta::CPAN

# -----------------------------------------------------------------------------
# Tripletail::Debug - TL デバッグ用クラス
# -----------------------------------------------------------------------------
package Tripletail::Debug;
use strict;
use warnings;
use Data::Dumper ();
use Tripletail;

sub _INIT_HOOK_PRIORITY() { 1_000_000_000 }; # 順序は問わない。
sub _PRE_REQUEST_HOOK_PRIORITY() { 1_000_000_000 } # 最後でなければならない。 
sub _OUTPUT_FILTER_PRIORITY() { 1_000_000_000 } # 最後でなければならない。

our $_INSTANCE;

1;

sub _getInstance {
	my $class = shift;

	if(!$_INSTANCE) {
		$_INSTANCE = $class->__new(@_);
	}

	$_INSTANCE;
}


sub __new {
	my $class = shift;
	my $group = shift;
	my $this = bless {} => $class;

	$this->{group} = defined $group ? $group : 'Debug';
	$this->{enabled} = $TL->INI->get($this->{group} => enable_debug => undef);
	$this->{popup_type} = $TL->INI->get($this->{group} => 'popup_type', 'none');

	$this->{warn_logging} = $TL->INI->get($this->{group} => 'warn_logging', 1);
	$this->{warn_popup} = $TL->INI->get($this->{group} => 'warn_popup', 1);

	$this->{log_popup} = $TL->INI->get($this->{group} => 'log_popup', 1);

	$this->{request_logging} = $TL->INI->get($this->{group} => 'request_logging', 1);
	$this->{request_popup} = $TL->INI->get($this->{group} => 'request_popup', 1);
	$this->{request_logging_max} = $TL->parseQuantity($TL->INI->get($this->{group} => 'request_logging_max', 0));

	$this->{content_logging} = $TL->INI->get($this->{group} => 'content_logging', 1);
	$this->{content_popup} = $TL->INI->get($this->{group} => 'content_popup', 1);
	$this->{content_logging_max} = $TL->parseQuantity($TL->INI->get($this->{group} => 'content_logging_max', 0));
	$this->{content_popup_max} = $TL->parseQuantity($TL->INI->get($this->{group} => 'content_popup_max', 0));

	$this->{template_logging} = $TL->INI->get($this->{group} => 'template_logging', 1);
	$this->{template_popup} = $TL->INI->get($this->{group} => 'template_popup', 1);

	$this->{db_logging} = $TL->INI->get($this->{group} => 'db_logging', 1);
	$this->{db_popup} = $TL->INI->get($this->{group} => 'db_popup', 1);
	$this->{db_logging_level} = $TL->INI->get($this->{group} => 'db_logging_level', 1);
	$this->{db_profile} = $TL->INI->get($this->{group} => 'db_profile', 1);

	$this->{location_debug} = $TL->INI->get($this->{group} => 'location_debug', 0);

	$this->reset;

	if($this->{enabled}) {
		# 最後に呼ばれるpreRequestハンドラを登録。
		$TL->setHook(
			'preRequest',
			_PRE_REQUEST_HOOK_PRIORITY,
			sub {
				if($this->{request_logging}) {
					$this->__log_request;
				}
			},
		);

		# 最初に呼ばれるinitハンドラを登録。
		$TL->setHook(
			'init',
			_INIT_HOOK_PRIORITY,
			sub {
				# 自分自身をContentFilterとして登録。
				$TL->setContentFilter(
					[__PACKAGE__, _OUTPUT_FILTER_PRIORITY], this => $this
				);
			},
		);

		if($this->{warn_logging} or $this->{warn_popup}) {
			$SIG{__WARN__} = sub {
				my $msg = shift;

				Tripletail::_isa($msg, 'Tripletail::Error') or $msg = $TL->newError(warn => $msg);



( run in 0.811 second using v1.01-cache-2.11-cpan-98e64b0badf )