Fix syntax error in example
[dbsrgits/SQL-Abstract.git] / lib / SQL / Abstract / Parts.pm
CommitLineData
10ef31e2 1package SQL::Abstract::Parts;
2
77ec9556 3use Module::Runtime ();
4use Scalar::Util ();
10ef31e2 5use strict;
6use warnings;
7
8use overload '""' => 'stringify', fallback => 1;
9
10sub new {
77ec9556 11 my ($proto, $join, @parts) = @_;
12 bless([
13 $join, map Scalar::Util::blessed($_) ? [ @$_ ] : $_, @parts
14 ], ref($proto) || $proto);
10ef31e2 15}
16
17sub stringify {
18 my ($self) = @_;
19 my ($join, @parts) = @$self;
b7516a3a 20 return join($join, map +(ref() ? stringify($_) : $_), @parts);
77ec9556 21}
22
23sub to_array { return @{$_[0]} }
24
b7516a3a 25sub formatter {
77ec9556 26 my ($self, %opts) = @_;
addf04c4 27 require SQL::Abstract::Formatter;
28 SQL::Abstract::Formatter->new(%opts)
b7516a3a 29}
30
31sub format {
32 my ($self, %opts) = @_;
33 $self->formatter(%opts)
34 ->format($self->to_array);
10ef31e2 35}
36
371;