Fey::Literal - Factory for making a literal piece of a SQL statement


Fey documentation Contained in the Fey distribution.

Index


Code Index:

NAME

Top

Fey::Literal - Factory for making a literal piece of a SQL statement

VERSION

Top

version 0.40

SYNOPSIS

Top

  my $literal = Fey::Literal->new_from_scalar($string_or_number_or_undef);

DESCRIPTION

Top

This class is a factory for creating a literal piece of a SQL statement, such as a string, number, or function.

METHODS

Top

This class provides the following methods:

Fey::Literal->new_from_scalar($scalar)

Given a string, number, or undef, this method returns a new object of the appropriate subclass. This will be either a Fey::Literal::String, Fey::Literal::Number, or Fey::Literal::Null.

BUGS

Top

See Fey for details on how to report bugs.

AUTHOR

Top

Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE

Top


Fey documentation Contained in the Fey distribution.

package Fey::Literal;
BEGIN {
  $Fey::Literal::VERSION = '0.40';
}

use strict;
use warnings;
use namespace::autoclean;

use Fey::FakeDBI;
use Fey::Literal::Function;
use Fey::Literal::Null;
use Fey::Literal::Number;
use Fey::Literal::String;
use Fey::Literal::Term;
use Fey::Types;
use Scalar::Util qw( blessed looks_like_number );
use overload ();

# This needs to come before we load subclasses or shit blows up
# because we end up with a metaclass object that is a
# Class::MOP::Class, not Moose::Meta::Class.
use Moose;
use MooseX::SemiAffordanceAccessor;
use MooseX::StrictConstructor;

sub new_from_scalar {
    shift;
    my $val = shift;

    return Fey::Literal::Null->new()
        unless defined $val;

    # Freaking Perl overloading is so broken! An overloaded reference
    # will not pass the type constraints, so we need to manually
    # convert it to a non-ref.
    if ( blessed $val && overload::Overloaded($val) ) {

        # The stringification method will be derived from the
        # numification method if needed. This might produce strange
        # results in the case of something that overloads both
        # operations, like a number class that returns either 2 or
        # "two", but in that case the author of the class made our
        # life impossible anyway ;)
        $val = $val . '';
    }

    return looks_like_number($val)
        ? Fey::Literal::Number->new($val)
        : Fey::Literal::String->new($val);
}

__PACKAGE__->meta()->make_immutable();

1;

# ABSTRACT: Factory for making a literal piece of a SQL statement




__END__