| 1 | ##---------------------------------------------------------------------------- | ||||||||||
| 2 | ## Database Object Interface - ~/lib/DB/Object/Fields/Overloaded.pm | ||||||||||
| 3 | ## Version v0.2.0 | ||||||||||
| 4 | ## Copyright(c) 2023 DEGUEST Pte. Ltd. | ||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||
| 6 | ## Created 2020/01/01 | ||||||||||
| 7 | ## Modified 2026/03/22 | ||||||||||
| 8 | ## All rights reserved | ||||||||||
| 9 | ## | ||||||||||
| 10 | ## | ||||||||||
| 11 | ## This program is free software; you can redistribute it and/or modify it | ||||||||||
| 12 | ## under the same terms as Perl itself. | ||||||||||
| 13 | ##---------------------------------------------------------------------------- | ||||||||||
| 14 | package DB::Object::Fields::Overloaded; | ||||||||||
| 15 | BEGIN | ||||||||||
| 16 | { | ||||||||||
| 17 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 3 | ▶ | use parent qw( DB::Object::Query::Element ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 3 | ▶ | use vars qw( $VERSION $EXCEPTION_CLASS ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | use overload ( | ||||||||||
| 22 | 20 | ▶ | '""' => sub{ return( $_[0]->{expression} ) }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 120 | ▶ | 'bool' => sub{1}, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 3 | fallback => 1, | |||||||||
| 25 | 3 | ▶ | ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 3 | ▶ | our $EXCEPTION_CLASS = $DB::Object::EXCEPTION_CLASS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 3 | our $VERSION = 'v0.2.0'; | |||||||||
| 28 | }; | ||||||||||
| 29 | |||||||||||
| 30 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | |||||||||||
| 33 | sub init | ||||||||||
| 34 | { | ||||||||||
| 35 | 20 | ▶ | my $self = shift( @_ ); | ||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 36 | 20 | $self->{expression} = undef; | |||||||||
| 37 | 20 | $self->{_init_strict_use_sub} = 1; | |||||||||
| 38 | 20 | $self->{_exception_class} = $EXCEPTION_CLASS; | |||||||||
| 39 | 20 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 20 | return( $self ); | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | # sub binded { return( shift->{binded} ); } | ||||||||||
| 44 | |||||||||||
| 45 | # For example, if a placeholder was $1 (PostgreSQL), or ?1 (SQLite), the binded_offset value would be 1 | ||||||||||
| 46 | # sub binded_offset { return( shift->{binded_offset} ); } | ||||||||||
| 47 | |||||||||||
| 48 | 20 | ▶ | sub expression { return( shift->_set_get_scalar( 'expression', @_ ) ); } | ||||||||
|
Subroutine
expression: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 49 | |||||||||||
| 50 | 3 | 1; | |||||||||
| 51 | # NOTE: POD | ||||||||||
| 52 | __END__ | ||||||||||
| 53 | |||||||||||
| 54 | =encoding utf-8 | ||||||||||
| 55 | |||||||||||
| 56 | =head1 NAME | ||||||||||
| 57 | |||||||||||
| 58 | DB::Object::Fields::Overloaded - Overloaded Field Class | ||||||||||
| 59 | |||||||||||
| 60 | =head1 SYNOPSIS | ||||||||||
| 61 | |||||||||||
| 62 | use DB::Object::Fields::Overloaded; | ||||||||||
| 63 | my $this = DB::Object::Fields::Overloaded->new( | ||||||||||
| 64 | # like field = $value | ||||||||||
| 65 | expression => $some_sql_expression, | ||||||||||
| 66 | field => $some_field, | ||||||||||
| 67 | type => $type, | ||||||||||
| 68 | value => $some_value, | ||||||||||
| 69 | ) || die( DB::Object::Fields::Overloaded->error, "\n" ); | ||||||||||
| 70 | |||||||||||
| 71 | =head1 VERSION | ||||||||||
| 72 | |||||||||||
| 73 | v0.2.0 | ||||||||||
| 74 | |||||||||||
| 75 | =head1 DESCRIPTION | ||||||||||
| 76 | |||||||||||
| 77 | The purpose of this package is to tag overloaded operation so we can handle them properly later such as in a where clause | ||||||||||
| 78 | |||||||||||
| 79 | =head1 METHODS | ||||||||||
| 80 | |||||||||||
| 81 | =head2 expression | ||||||||||
| 82 | |||||||||||
| 83 | Sets or gets the resulting expression from the overloaded field resulting from an operation. | ||||||||||
| 84 | |||||||||||
| 85 | =head1 AUTHOR | ||||||||||
| 86 | |||||||||||
| 87 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||||||||||
| 88 | |||||||||||
| 89 | =head1 SEE ALSO | ||||||||||
| 90 | |||||||||||
| 91 | L<DB::Object::Fields::Field>, L<DB::Object::Fields>, L<DB::Object::Fields::Unknown> | ||||||||||
| 92 | |||||||||||
| 93 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 94 | |||||||||||
| 95 | Copyright(c) 2021-2023 DEGUEST Pte. Ltd. | ||||||||||
| 96 | |||||||||||
| 97 | All rights reserved | ||||||||||
| 98 | |||||||||||
| 99 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||
| 100 | |||||||||||
| 101 | =cut | ||||||||||