File: Parts.pm

package info (click to toggle)
libsql-abstract-perl 2.000001-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 744 kB
  • sloc: perl: 3,443; makefile: 8
file content (37 lines) | stat: -rw-r--r-- 697 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package SQL::Abstract::Parts;

use Module::Runtime ();
use Scalar::Util ();
use strict;
use warnings;

use overload '""' => 'stringify', fallback => 1;

sub new {
  my ($proto, $join, @parts) = @_;
  bless([
    $join, map Scalar::Util::blessed($_) ? [ @$_ ] : $_, @parts
  ], ref($proto) || $proto);
}

sub stringify {
  my ($self) = @_;
  my ($join, @parts) = @$self;
  return join($join, map +(ref() ? stringify($_) : $_), @parts);
}

sub to_array { return @{$_[0]} }

sub formatter {
  my ($self, %opts) = @_;
  require SQL::Abstract::Formatter;
  SQL::Abstract::Formatter->new(%opts)
}

sub format {
  my ($self, %opts) = @_;
  $self->formatter(%opts)
       ->format($self->to_array);
}

1;