merge configs with profiles
[dbsrgits/SQL-Abstract.git] / lib / SQL / Abstract / Tree.pm
index 36a2ce9..ada82df 100644 (file)
@@ -5,6 +5,25 @@ use warnings;
 use Carp;
 
 use List::Util;
+use Hash::Merge 'merge';
+
+Hash::Merge::specify_behavior({
+   SCALAR => {
+      SCALAR => sub { $_[1] },
+      ARRAY  => sub { [ $_[0], @{$_[1]} ] },
+      HASH   => sub { $_[1] },
+   },
+   ARRAY => {
+      SCALAR => sub { $_[1] },
+      ARRAY  => sub { $_[1] },
+      HASH   => sub { $_[1] },
+   },
+   HASH => {
+      SCALAR => sub { $_[1] },
+      ARRAY  => sub { [ values %{$_[0]}, @{$_[1]} ] },
+      HASH   => sub { Hash::Merge::_merge_hashes( $_[0], $_[1] ) },
+   },
+}, 'My Behavior' );
 
 use base 'Class::Accessor::Grouped';
 
@@ -103,6 +122,7 @@ my %indents = (
 
 my %profiles = (
    console => {
+      fill_in_placeholders => 1,
       indent_string => ' ',
       indent_amount => 2,
       newline       => "\n",
@@ -110,6 +130,7 @@ my %profiles = (
       indentmap     => { %indents },
    },
    console_monochrome => {
+      fill_in_placeholders => 1,
       indent_string => ' ',
       indent_amount => 2,
       newline       => "\n",
@@ -117,6 +138,7 @@ my %profiles = (
       indentmap     => { %indents },
    },
    html => {
+      fill_in_placeholders => 1,
       indent_string => ' ',
       indent_amount => 2,
       newline       => "<br />\n",
@@ -167,10 +189,11 @@ eval {
 };
 
 sub new {
-   my ($class, $args) = @_;
+   my $class = shift;
+   my $args  = shift || {};
 
    my $profile = delete $args->{profile} || 'none';
-   my $data = {%{$profiles{$profile}}, %{$args||{}}};
+   my $data = merge( $profiles{$profile}, $args );
 
    bless $data, $class
 }
@@ -278,7 +301,6 @@ sub format_keyword {
   return $keyword
 }
 
-
 my %starters = (
    select        => 1,
    update        => 1,