Pangloss::Language - a language in Pangloss.


Pangloss documentation Contained in the Pangloss distribution.

Index


Code Index:

NAME

Top

Pangloss::Language - a language in Pangloss.

SYNOPSIS

Top

  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();

DESCRIPTION

Top

This class represents a language in Pangloss.

It inherits from Pangloss::StoredObject::Common and Pangloss::Collection::Item.

EXPORTS

Top

Exports two constants on request for use with language direction:

  dir_LTR (left to right)
  dir_RTL (right to left)

METHODS

Top

$obj->iso_code()

set/get ISO code.

$obj->direction()

set/get language direction.

$bool = $obj->is_ltr(), $obj->is_rtl()

test if the language direction is the above.

AUTHOR

Top

Steve Purkis <spurkis@quiup.com>

SEE ALSO

Top

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__

#------------------------------------------------------------------------------