| 1 |
# |
| 2 |
# $Id: Value.pm 852 2007-03-01 20:32:37Z bastian $ |
| 3 |
# |
| 4 |
# Perl module for Kamailio |
| 5 |
# |
| 6 |
# Copyright (C) 2006 Collax GmbH |
| 7 |
# (Bastian Friedrich <[email protected]>) |
| 8 |
# |
| 9 |
# This file is part of Kamailio, a free SIP server. |
| 10 |
# |
| 11 |
# Kamailio is free software; you can redistribute it and/or modify |
| 12 |
# it under the terms of the GNU General Public License as published by |
| 13 |
# the Free Software Foundation; either version 2 of the License, or |
| 14 |
# (at your option) any later version |
| 15 |
# |
| 16 |
# Kamailio is distributed in the hope that it will be useful, |
| 17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
# GNU General Public License for more details. |
| 20 |
# |
| 21 |
# You should have received a copy of the GNU General Public License |
| 22 |
# along with this program; if not, write to the Free Software |
| 23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 24 |
# |
| 25 |
|
| 26 |
=head1 Kamailio::VDB::Value |
| 27 |
|
| 28 |
This package represents a database value. Additional to the data itself, |
| 29 |
information about its type is stored. |
| 30 |
|
| 31 |
=head2 stringification |
| 32 |
|
| 33 |
When accessing a Kamailio::VDB::Value object as a string, it simply returns its data |
| 34 |
regardless of its type. |
| 35 |
=cut |
| 36 |
|
| 37 |
use strict; |
| 38 |
|
| 39 |
package Kamailio::VDB::Value; |
| 40 |
|
| 41 |
use overload '""' => \&stringify; |
| 42 |
|
| 43 |
sub stringify { shift->{data} } |
| 44 |
|
| 45 |
use Kamailio; |
| 46 |
use Kamailio::Constants; |
| 47 |
|
| 48 |
our @ISA = qw ( Kamailio::Utils::Debug ); |
| 49 |
|
| 50 |
=head2 new(type,data) |
| 51 |
|
| 52 |
Constructs a new Value object. Its data type and the data are passed as |
| 53 |
parameters. |
| 54 |
|
| 55 |
=cut |
| 56 |
|
| 57 |
sub new { |
| 58 |
my $class = shift; |
| 59 |
my $type = shift; |
| 60 |
my $data = shift; |
| 61 |
|
| 62 |
my $self = { |
| 63 |
type => $type, |
| 64 |
data => $data, |
| 65 |
}; |
| 66 |
|
| 67 |
bless $self, $class; |
| 68 |
|
| 69 |
return $self; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
=head2 type() |
| 74 |
|
| 75 |
Returns or sets the current data type. Please consider using the constants |
| 76 |
from Kamailio::Constants |
| 77 |
|
| 78 |
=cut |
| 79 |
|
| 80 |
sub type { |
| 81 |
my $self = shift; |
| 82 |
if (@_) { |
| 83 |
$self->{type} = shift; |
| 84 |
} |
| 85 |
|
| 86 |
return $self->{type}; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
=head2 data() |
| 91 |
|
| 92 |
Returns or sets the current data. |
| 93 |
|
| 94 |
=cut |
| 95 |
|
| 96 |
sub data { |
| 97 |
my $self = shift; |
| 98 |
if (@_) { |
| 99 |
$self->{data} = shift; |
| 100 |
} |
| 101 |
|
| 102 |
return $self->{data}; |
| 103 |
} |
| 104 |
|
| 105 |
1; |