| 1 | package Fey::Literal; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 27 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 27 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 27 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 27 | our $VERSION = '0.42'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 27 | ▶ | use Fey::FakeDBI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 27 | ▶ | use Fey::Literal::Function; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 27 | ▶ | use Fey::Literal::Null; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 27 | ▶ | use Fey::Literal::Number; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 27 | ▶ | use Fey::Literal::String; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 27 | ▶ | use Fey::Literal::Term; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 27 | ▶ | use Fey::Types; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 27 | ▶ | use Scalar::Util qw( blessed looks_like_number ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 27 | ▶ | use overload (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # This needs to come before we load subclasses or shit blows up | ||||||||||||||||||||||||||||
| 20 | # because we end up with a metaclass object that is a | ||||||||||||||||||||||||||||
| 21 | # Class::MOP::Class, not Moose::Meta::Class. | ||||||||||||||||||||||||||||
| 22 | 27 | ▶ | use Moose 0.90; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 27 | ▶ | use MooseX::SemiAffordanceAccessor 0.03; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 27 | ▶ | use MooseX::StrictConstructor 0.07; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub new_from_scalar { | ||||||||||||||||||||||||||||
| 27 | 235 | ▶ | shift; | ||||||||||||||||||||||||||
|
Subroutine
new_from_scalar: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 235 | my $val = shift; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 235 | ▶ | return Fey::Literal::Null->new() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | unless defined $val; | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # Freaking Perl overloading is so broken! An overloaded reference | ||||||||||||||||||||||||||||
| 34 | # will not pass the type constraints, so we need to manually | ||||||||||||||||||||||||||||
| 35 | # convert it to a non-ref. | ||||||||||||||||||||||||||||
| 36 | 224 | ▶ | if ( blessed $val && overload::Overloaded($val) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($val) and overload::Overloaded($val)
MC/DC50%1/2
builtin::blessed($val) and overload::Overloaded($val)
builtin::blessed($val)
overload::Overloaded($val)
Truth table66%2/3
A and B
A= builtin::blessed($val)B= overload::Overloaded($val)
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # The stringification method will be derived from the | ||||||||||||||||||||||||||||
| 39 | # numification method if needed. This might produce strange | ||||||||||||||||||||||||||||
| 40 | # results in the case of something that overloads both | ||||||||||||||||||||||||||||
| 41 | # operations, like a number class that returns either 2 or | ||||||||||||||||||||||||||||
| 42 | # "two", but in that case the author of the class made our | ||||||||||||||||||||||||||||
| 43 | # life impossible anyway ;) | ||||||||||||||||||||||||||||
| 44 | 2 | $val = $val . ''; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 224 | ▶ | return looks_like_number($val) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | ? Fey::Literal::Number->new($val) | ||||||||||||||||||||||||||||
| 49 | : Fey::Literal::String->new($val); | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 27 | __PACKAGE__->meta()->make_immutable(); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 27 | 1; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # ABSTRACT: Factory for making a literal piece of a SQL statement | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | __END__ | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =pod | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head1 NAME | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | Fey::Literal - Factory for making a literal piece of a SQL statement | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head1 VERSION | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | version 0.42 | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | my $literal = Fey::Literal->new_from_scalar($string_or_number_or_undef); | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | This class is a factory for creating a literal piece of a SQL statement, such | ||||||||||||||||||||||||||||
| 77 | as a string, number, or function. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head1 METHODS | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | This class provides the following methods: | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head2 Fey::Literal->new_from_scalar($scalar) | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | Given a string, number, or undef, this method returns a new object of | ||||||||||||||||||||||||||||
| 86 | the appropriate subclass. This will be either a | ||||||||||||||||||||||||||||
| 87 | C<Fey::Literal::String>, C<Fey::Literal::Number>, or | ||||||||||||||||||||||||||||
| 88 | C<Fey::Literal::Null>. | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =head1 BUGS | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | See L<Fey> for details on how to report bugs. | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | Dave Rolsky <autarch@urth.org> | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | This software is Copyright (c) 2011 - 2015 by Dave Rolsky. | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | This is free software, licensed under: | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | The Artistic License 2.0 (GPL Compatible) | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =cut | ||||||||||||||||||||||||||||