File Coverage

blib/lib/Fey/Literal.pm
Criterion Covered Total %
statement 14 16 87.5
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 20 22 90.9


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