From: Arthur Axel 'fREW' Schmidt Date: Thu, 9 Sep 2010 03:32:08 +0000 (-0500) Subject: DBIC_TRACE_PROFILE X-Git-Tag: v0.08124~83 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b6cd6;p=dbsrgits%2FDBIx-Class.git DBIC_TRACE_PROFILE --- diff --git a/Changes b/Changes index 70cd7f8..00603f2 100644 --- a/Changes +++ b/Changes @@ -9,6 +9,9 @@ Revision history for DBIx::Class most of the heavy lifting for a while anyway - FilterColumn now passes data through when transformations are not specified rather than throwing an exception. + - Use DBIx::Class::Storage::Debug::PrettyPrint when the + environment variable DBIC_TRACE_PROFILE is set, see + DBIx::Class::Storage for more information * Fixes - Fixed rels ending with me breaking subqueried limit realiasing diff --git a/Makefile.PL b/Makefile.PL index 40806a1..a714900 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -56,7 +56,7 @@ my $runtime_requires = { 'MRO::Compat' => '0.09', 'Module::Find' => '0.06', 'Path::Class' => '0.18', - 'SQL::Abstract' => '1.67', + 'SQL::Abstract' => '1.68', 'Sub::Name' => '0.04', 'Data::Dumper::Concise' => '1.000', 'Scope::Guard' => '0.03', @@ -65,6 +65,7 @@ my $runtime_requires = { 'namespace::clean' => '0.14', 'Math::BigInt' => '1.89', 'Math::Base36' => '0.07', + 'Config::Any' => '0.20', }; # this is so we can order requires alphabetically diff --git a/lib/DBIx/Class/Storage.pm b/lib/DBIx/Class/Storage.pm index 9f7ed68..34c3eac 100644 --- a/lib/DBIx/Class/Storage.pm +++ b/lib/DBIx/Class/Storage.pm @@ -63,9 +63,22 @@ sub new { bless $new, $self; $new->set_schema($schema); - $new->debugobj(new DBIx::Class::Storage::Statistics()); - - #my $fh; + my $debugobj; + if (my $profile = $ENV{DBIC_TRACE_PROFILE}) { + require DBIx::Class::Storage::Debug::PrettyPrint; + if ($profile =~ /^\.?\//) { + require Config::Any; + my $cfg = Config::Any->load_files({ files => [$profile], use_ext => 1 }); + + my ($filename, $config) = %{$cfg->[0]}; + $debugobj = DBIx::Class::Storage::Debug::PrettyPrint->new($config) + } else { + $debugobj = DBIx::Class::Storage::Debug::PrettyPrint->new({ profile => $profile }) + } + } else { + $debugobj = DBIx::Class::Storage::Statistics->new + } + $new->debugobj($debugobj); my $debug_env = $ENV{DBIX_CLASS_STORAGE_DBI_DEBUG} || $ENV{DBIC_TRACE}; @@ -487,6 +500,16 @@ created (when you call connect on your schema). So, run-time changes to this environment variable will not take effect unless you also re-connect on your schema. +=head2 DBIC_TRACE_PROFILE + +If C is set, L +will be used to format the output from C. The value it +is set to is the C that it will be used. If the value is a +filename the file is read with L and the results are +used as the configuration for tracing. See L +for what that structure should look like. + + =head2 DBIX_CLASS_STORAGE_DBI_DEBUG Old name for DBIC_TRACE diff --git a/t/lib/awesome.json b/t/lib/awesome.json new file mode 100644 index 0000000..9700520 --- /dev/null +++ b/t/lib/awesome.json @@ -0,0 +1,2 @@ +{"indent_string":"frioux"} + diff --git a/t/storage/dbic_pretty.t b/t/storage/dbic_pretty.t new file mode 100644 index 0000000..ab19c8a --- /dev/null +++ b/t/storage/dbic_pretty.t @@ -0,0 +1,33 @@ +use strict; +use warnings; +use lib qw(t/lib); +use DBICTest; +use Test::More; + +BEGIN { delete @ENV{qw(DBIC_TRACE_PROFILE)} } + +{ + my $schema = DBICTest->init_schema; + + isa_ok($schema->storage->debugobj, 'DBIx::Class::Storage::Statistics'); +} + +{ + local $ENV{DBIC_TRACE_PROFILE} = 'console'; + + my $schema = DBICTest->init_schema; + + isa_ok($schema->storage->debugobj, 'DBIx::Class::Storage::Debug::PrettyPrint');; + is($schema->storage->debugobj->_sqlat->indent_string, ' ', 'indent string set correctly from console profile'); +} + +{ + local $ENV{DBIC_TRACE_PROFILE} = './t/lib/awesome.json'; + + my $schema = DBICTest->init_schema; + + isa_ok($schema->storage->debugobj, 'DBIx::Class::Storage::Debug::PrettyPrint');; + is($schema->storage->debugobj->_sqlat->indent_string, 'frioux', 'indent string set correctly from file-based profile'); +} + +done_testing;