# Copyright (c) 1999-2011 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: Gender.pm,v 2.4 2011/11/09 22:51:54 schellj Exp $ package Bivio::Type::Gender; use strict; use Bivio::Base 'Type.Enum'; our($VERSION) = sprintf('%d.%02d', q$Revision: 2.4 $ =~ /\d+/g); __PACKAGE__->compile([ UNKNOWN => [0, 'Unspecified'], FEMALE => [1, undef, undef, 'F'], MALE => [2, undef, undef, 'M'], ]); sub from_literal { my($proto, $value) = @_; my($res, $err) = shift->SUPER::from_literal(@_); if ($err) { if ($value =~ /^m$/i) { $res = $proto->MALE; $err = undef; } elsif ($value =~ /^f$/i) { $res = $proto->FEMALE; $err = undef; } } return $err ? ($res, $err) : $res; } 1;