| 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 | use strict; | ||
| 18 | use warnings; | ||
| 19 | use parent qw( DB::Object::Query::Element ); | ||
| 20 | use vars qw( $VERSION $EXCEPTION_CLASS ); | ||
| 21 | use overload ( | ||
| 22 | '""' => sub{ return( $_[0]->{expression} ) }, | ||
| 23 | 'bool' => sub{1}, | ||
| 24 | fallback => 1, | ||
| 25 | ); | ||
| 26 | our $EXCEPTION_CLASS = $DB::Object::EXCEPTION_CLASS; | ||
| 27 | our $VERSION = 'v0.2.0'; | ||
| 28 | }; | ||
| 29 | |||
| 30 | use strict; | ||
| 31 | use warnings; | ||
| 32 | |||
| 33 | sub init | ||
| 34 | { | ||
| 35 | my $self = shift( @_ ); | ||
| 36 | $self->{expression} = undef; | ||
| 37 | $self->{_init_strict_use_sub} = 1; | ||
| 38 | $self->{_exception_class} = $EXCEPTION_CLASS; | ||
| 39 | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||
| 40 | 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 | sub expression { return( shift->_set_get_scalar( 'expression', @_ ) ); } | ||
| 49 | |||
| 50 | 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 |