File Coverage

blib/lib/Fey/Literal.pm
Criterion Covered Total %
statement 51 51 100.0
branch 6 6 100.0
condition 2 3 66.6
subroutine 16 16 100.0
pod 1 1 100.0
total 76 77 98.7


line stmt bran cond sub pod time code
1             package Fey::Literal;
2              
3 28     28   16367 use strict;
  28         42  
  28         975  
4 28     28   128 use warnings;
  28         40  
  28         628  
5 28     28   581 use namespace::autoclean;
  28         18498  
  28         146  
6              
7             our $VERSION = '0.42';
8              
9 28     28   10839 use Fey::FakeDBI;
  28         56  
  28         793  
10 28     28   9369 use Fey::Literal::Function;
  28         96  
  28         1592  
11 28     28   14269 use Fey::Literal::Null;
  28         2251  
  28         1087  
12 28     28   13552 use Fey::Literal::Number;
  28         81  
  28         1113  
13 28     28   13471 use Fey::Literal::String;
  28         97  
  28         1163  
14 28     28   14225 use Fey::Literal::Term;
  28         91  
  28         1105  
15 28     28   215 use Fey::Types;
  28         36  
  28         170  
16 28     28   2634 use Scalar::Util qw( blessed looks_like_number );
  28         43  
  28         1844  
17 28     28   166 use overload ();
  28         47  
  28         833  
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 28     28   118 use Moose 0.90;
  28         729  
  28         248  
23 28     28   144857 use MooseX::SemiAffordanceAccessor 0.03;
  28         654  
  28         195  
24 28     28   76178 use MooseX::StrictConstructor 0.07;
  28         591  
  28         174  
25              
26             sub new_from_scalar {
27 243     243 1 1135 shift;
28 243         346 my $val = shift;
29              
30 243 100       911 return Fey::Literal::Null->new()
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 232 100 66     840 if ( blessed $val && 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         150 $val = $val . '';
45             }
46              
47 232 100       7810 return looks_like_number($val)
48             ? Fey::Literal::Number->new($val)
49             : Fey::Literal::String->new($val);
50             }
51              
52             __PACKAGE__->meta()->make_immutable();
53              
54             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