| 1 | #!/usr/bin/perl | ||||||||||||||||||||
| 2 | package SQL::QueryBuilder::Pretty; | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | use Module::Pluggable | ||||||||||||||||||||
| 13 | 2 | ▶ | 'search_path' => [ | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 'SQL::QueryBuilder::Pretty::Database::ANSI', | ||||||||||||||||||||
| 15 | ], | ||||||||||||||||||||
| 16 | 'instantiate' => 'new', | ||||||||||||||||||||
| 17 | 'sub_name' => 'rules' | ||||||||||||||||||||
| 18 | 2 | ; | |||||||||||||||||||
| 19 | 2 | ▶ | use SQL::QueryBuilder::Pretty::Print; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||
| 22 | 0 | my $class = shift; | |||||||||||||||||||
| 23 | 0 | my %self = @_; | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 0 | ▶ | if ( my $database = delete $self{'-database'} ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 26 | 0 | $class = CORE::join( q{::}, $class, 'Database', $database ); | |||||||||||||||||||
| 27 | 0 | ▶ | eval "use $class; 1" or croak $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | 0 | return $class->new( %self ); | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | elsif ( my $handler = delete $self{'-handler'} ) { | ||||||||||||||||||||
| 31 | 0 | $class = CORE::join( q{::}, $class, 'Handler', ref $handler ); | |||||||||||||||||||
| 32 | 0 | ▶ | eval "use $class; 1" or croak $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 0 | return $class->new( %self, 'handler' => $handler ); | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | else { | ||||||||||||||||||||
| 36 | 0 | ▶ | return bless { %self }, ref $class || $class; | ||||||||||||||||||
|
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | ▶ | sub print { | ||||||||||||||||||
|
Subroutine
print: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 41 | 0 | my $self = shift; | |||||||||||||||||||
| 42 | 0 | my $query = shift; | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | # Initializes the print object | ||||||||||||||||||||
| 45 | 0 | my $print = SQL::QueryBuilder::Pretty::Print->new( %{ $self } ); | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | # Get rules in the correct order | ||||||||||||||||||||
| 48 | # TODO: load unique rules by name | ||||||||||||||||||||
| 49 | 0 | my @rules = sort { $a->order <=> $b->order } $self->rules(); | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 0 | ▶ | while ( $query ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 0 | for my $rule ( @rules ) { | |||||||||||||||||||
| 53 | 0 | my $match = $rule->match; | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | ▶ | if ( $query =~ s/^($match)//smx ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | # A rule can exit in error, in that case continue trying | ||||||||||||||||||||
| 57 | 0 | ▶ | last if $rule->action($print, $1); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 0 | return $print->query; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 2 | 1; | |||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||