better followiung principles
[scpubgit/Q-Branch.git] / lib / SQL / Abstract / Parts.pm
CommitLineData
b84764fb 1package SQL::Abstract::Parts;
2
b3b54441 3use Module::Runtime ();
4use Scalar::Util ();
b84764fb 5use strict;
6use warnings;
7
8use overload '""' => 'stringify', fallback => 1;
9
10sub new {
b3b54441 11 my ($proto, $join, @parts) = @_;
12 bless([
13 $join, map Scalar::Util::blessed($_) ? [ @$_ ] : $_, @parts
14 ], ref($proto) || $proto);
b84764fb 15}
16
17sub stringify {
18 my ($self) = @_;
07070f1a 19::Dwarn([ STR => $self ]);
b84764fb 20 my ($join, @parts) = @$self;
07070f1a 21 return join($join, map +(ref() ? stringify($_) : $_), @parts);
b3b54441 22}
23
24sub to_array { return @{$_[0]} }
25
07070f1a 26sub formatter {
b3b54441 27 my ($self, %opts) = @_;
28 Module::Runtime::use_module('SQL::Abstract::Formatter')
29 ->new(%opts)
07070f1a 30}
31
32sub format {
33 my ($self, %opts) = @_;
34 $self->formatter(%opts)
35 ->format($self->to_array);
b84764fb 36}
37
381;