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   15359 use strict;
  28         45  
  28         937  
4 28     28   207 use warnings;
  28         49  
  28         690  
5 28     28   580 use namespace::autoclean;
  28         15105  
  28         146  
6              
7             our $VERSION = '0.43';
8              
9 28     28   11434 use Fey::FakeDBI;
  28         61  
  28         771  
10 28     28   9739 use Fey::Literal::Function;
  28         154  
  28         1936  
11 28     28   16695 use Fey::Literal::Null;
  28         2825  
  28         1240  
12 28     28   14584 use Fey::Literal::Number;
  28         105  
  28         1224  
13 28     28   15509 use Fey::Literal::String;
  28         97  
  28         1192  
14 28     28   15246 use Fey::Literal::Term;
  28         101  
  28         1263  
15 28     28   241 use Fey::Types;
  28         45  
  28         185  
16 28     28   2760 use Scalar::Util qw( blessed looks_like_number );
  28         43  
  28         1930  
17 28     28   145 use overload ();
  28         47  
  28         923  
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   131 use Moose 2.1200;
  28         909  
  28         244  
23 28     28   159376 use MooseX::SemiAffordanceAccessor 0.03;
  28         820  
  28         193  
24 28     28   83731 use MooseX::StrictConstructor 0.13;
  28         680  
  28         179  
25              
26             sub new_from_scalar {
27 243     243 1 1805 shift;
28 243         422 my $val = shift;
29              
30 243 100       1007 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     934 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         165 $val = $val . '';
45             }
46              
47 232 100       8270 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.43
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