Leo Cacciari > Lingua-IT-Numbers > Lingua::IT::Numbers

Download:
Lingua-IT-Numbers-0.06.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.06   Source  

NAME ^

Lingua::IT::Numbers - Converts numeric values into their Italian string equivalents

SYNOPSIS ^

 # Procedural Style
 use Lingua::IT::Numbers qw(number_to_it);
 print number_to_it(315);
 # prints trecentoquindici

 print number_to_it(325.12)
 # prints trecentoventicinque virgola dodici

 print number_to_it(325.12,decmode => 'fract')
 # prints trecentoveticinque e dodici centesimi

 # OO Style
 use Lingua::IT::Numbers;
 my $number = Lingua::IT::Numbers->new( 123 );
 print $number->get_string; 
 print $number->get_ordinate;

DESCRIPTION ^

Lingua::IT::Numbers converts arbitrary numbers into human-oriented Italian text. The interface is sligtly different from that defined for Lingua::EN::Numbers, for one it can be used in a procedural way, just like Lingua::FR::Numbers, importing the number_to_it function.

Remark that Lingua::IT::Numbers object, created by the new constructor described below, are Two-face scalars as described in overload: when a Lingua::IT::Numbers object is used as a number, then it is a number, when it is used as a string then it is its Italian representation (see "OVERLOADING")

EXPORT

Nothing is exported by default. The following function is exported.

number_to_it($number,[options])

Converts a number to its Italian string representation without building the Lingua::IT::Numbers instance.

  $string = number_to_it($number,...);

is equivalent to

  $string = do {
    my $tmp = Lingua::IT::Numbers->new($number,...);
    $tmp->get_string();
  };

See "OPTIONS" for avalaible options for number_to_it

METHODS

The following method compose the OO interface to Lingua::IT::Numbers.

Lingua::IT::Numbers-new($number,[options])>

Creates and initialize an instance.

$obj->get_number

Returns the number contained in the instance.

$obj->get_string()

Returns the representation of the number as a string in Italian.

$obj->set_number($number)

Changes the number contained in the instance.

OPTIONS ^

The representation of numbers by Lingua::IT::Numbers can be influenced by means of options. Options are given either to the exported funcion number_to_it or to the constructor b<new> as named parameters. the following options are defined:

decimal

If different from zero is the minimal number of decimal places a number must have.

decmode

Can be either normal or fract. This options selects the method used for writing the fractional part of a number. Infact, in Italian there are two way to represent fractional numbers in writing. For 345.27 you can say either "trecentoquarantacinque virgola ventisette" or "trecentoquarantacinque e ventisette centesimi". The latter is used mainly for mensurament. Setting the decmode option to normal (its default value) selects the former method, while setting it to fract selects the latter.

name

The value of this option can be either a string or (a reference to) an array containing two strings. If the option value is a string this is interpolated between the integer part and the fractional part. If the option value is an array, the first element is taken to be the singular form while the second is the plural. So that

    my $euro = Lingua::IT::Numbers->new(253,name => "euro",
                                            decmode => 'fract',
                                            decimal => 2);
    print $euro->get_string(),"\n"

will print 'duecentocinquantatre euro e zero centesimi', while

    my $dollar = Lingua::IT::Numbers->new(253,name => [qw(dollaro dollari)],
                                              decmode => 'fract',
                                              decimal => 2);
    print $dollar->get_string(),"\n"

will print 'duecentocinquantatre dollari e zero centesimi'.

OVERLOADING ^

As stated above, instances of Lingua::IT::Numbers are Two-face scalars like those described in overload. This means that you can do something like:

    my $first = Lingua::IT::Numbers->new(123);
    my $second = Lingua::IT::Numbers->new(321);

    print $first,' + ',$second,' = ',$first+$second,"\n";

which will print: 'centoventitre + trecentoventuno = quattrocentoquarantaquattro'.

SEE ALSO ^

Lingua::*::Numbers, overload.

BUGS ^

There is no control on options' values.

TODO ^

AUTHOR ^

Leo "TheHobbit" Cacciari, <hobbit@cpan.org>

COPYRIGHT AND LICENSE ^

Copyright (C) 2004 by Leo "TheHobbit" Cacciari

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: