| Pangloss documentation | Contained in the Pangloss distribution. |
Pangloss::Language - a language in Pangloss.
use Pangloss::Language qw( dirRTL dirLTR );
my $language = new Pangloss::Language();
$language->name( $text )
->iso_code( $text )
->direction( dirRTL )
->creator( $user )
->notes( $text )
->date( time )
->validate;
# catch Pangloss::Language::Errors
do { ... } if $language->is_ltr();
This class represents a language in Pangloss.
It inherits from Pangloss::StoredObject::Common and Pangloss::Collection::Item.
Exports two constants on request for use with language direction:
dir_LTR (left to right) dir_RTL (right to left)
set/get ISO code.
set/get language direction.
test if the language direction is the above.
Steve Purkis <spurkis@quiup.com>
Pangloss, Pangloss::Language::Error, Pangloss::Languages
| Pangloss documentation | Contained in the Pangloss distribution. |
package Pangloss::Language; use strict; use warnings::register; use Error; use Pangloss::Language::Error; use Pangloss::StoredObject::Error; use base qw( Pangloss::StoredObject::Common Pangloss::Collection::Item Exporter ); use accessors qw( iso_code direction ); our $VERSION = ((require Pangloss::Version), $Pangloss::VERSION)[1]; our $REVISION = (split(/ /, ' $Revision: 1.11 $ '))[2]; our @EXPORT_OK = qw( dir_LTR dir_RTL ); use constant dir_LTR => 'ltr'; use constant dir_RTL => 'rtl'; sub key { my $self = shift; return $self->iso_code(); } sub is_ltr { my $self = shift; return ( $self->direction eq dir_LTR ); } sub is_rtl { my $self = shift; return ( $self->direction eq dir_RTL ); } sub validate { my $self = shift; my $errors = shift || {}; $errors->{eIsoCodeRequired()} = 1 unless ($self->iso_code); $errors->{eDirectionRequired()} = 1 unless ($self->direction); return $self->SUPER::validate( $errors ); } sub throw_invalid_error { my $self = shift; my $errors = shift; throw Pangloss::Language::Error( flag => eInvalid, language => $self, invalid => $errors ); } sub copy { my $self = shift; my $lang = shift; $self->SUPER::copy( $lang ) ->iso_code( $lang->iso_code ) ->direction( $lang->direction ); return $self; } 1; __END__ #------------------------------------------------------------------------------