# Copyright (c) 2007 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: Hash.pm,v 1.5 2008/01/09 18:18:22 nagler Exp $ package Bivio::Type::Hash; use strict; use Bivio::Base 'Bivio::Type'; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.5 $ =~ /\d+/g); my($_R) = __PACKAGE__->use('IO.Ref'); sub compare_defined { die('not supported'); } sub extract_by_keys { my(undef, $value, $to_include) = @_; return {map({ my($k) = $_; grep($k eq $_, @$to_include) ? ($k => $value->{$k}) : (); } keys(%$value))}; } sub is_equal { my(undef, $left, $right) = @_; return $_R->nested_equals($left, $right); } sub from_literal { my(undef, $value) = @_; return !defined($value) ? (undef, undef) : ref($value) eq 'HASH' ? $value : (undef, Bivio::TypeError->SYNTAX_ERROR); } sub from_sql_column { my(undef, $value) = @_; return $value && Bivio::Die->eval_or_die($value); } sub get_width { return 0xffff; } sub to_literal { return shift->to_sql_param(@_); } sub to_sql_param { my(undef, $value) = @_; return $value && ${$_R->to_string($value, 0, 0)}; } sub to_string { my(undef, $value) = @_; return !$value ? '' : join('; ', map({ my($v) = $value->{$_}; "$_: " . (!defined($v) ? '' : !ref($v) ? $v : ${Bivio::IO::Ref->to_string($v, 0, 0)}); } sort(keys(%$value)))); } 1;