# Copyright (c) 1999-2001 bivio Software, Inc. All rights reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: TypeValue.pm,v 2.5 2011/08/15 18:19:37 moeller Exp $ package Bivio::TypeValue; use strict; use Bivio::Base 'Collection.Attributes'; # Binds a type and a value. Convenient for parameter passing. our($VERSION) = sprintf('%d.%02d', q$Revision: 2.5 $ =~ /\d+/g); sub as_string { my($self) = @_; my($t) = $self->get('type'); my($v) = $self->get('value'); return (ref($t) || $t) . '[' . join(',', map($t->to_string($_), ref($v) eq 'ARRAY' ? @$v : $v)) . ']'; } sub equals { my($self, $that) = @_; return defined($that) && ref($self) eq ref($that) && $self->get('type') eq $that->get('type') && $self->get('type')->is_equal( $self->get('value'), $that->get('value')) ? 1 : 0; } sub new { my($proto, $type, $value) = @_; Bivio::Die->die($type, ': not a type') unless UNIVERSAL::isa($type, 'Bivio::Type'); return $proto->SUPER::new({ type => $type, value => $value, }); } 1;