This is an automated email from the git hooks/post-receive script.

dmn pushed a commit to annotated tag debian/0.43-2
in repository libconvert-units-perl.

commit a198593fc4de28db8b51d8b9ba0d6171ddd587a2
Author: Damyan Ivanov <d...@debian.org>
Date:   Tue Jul 21 19:13:09 2015 +0000

    Imported Upstream version 0.43
---
 Base.pm        | 330 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 Changes        |  19 ++++
 Length.pm      |  81 ++++++++++++++
 MANIFEST       |  11 ++
 Makefile.PL    |  14 +++
 README         | 157 +++++++++++++++++++++++++++
 Temperature.pm |  46 ++++++++
 Type.pm        |  56 ++++++++++
 test.pl        |  20 ++++
 9 files changed, 734 insertions(+)

diff --git a/Base.pm b/Base.pm
new file mode 100644
index 0000000..b7ac710
--- /dev/null
+++ b/Base.pm
@@ -0,0 +1,330 @@
+package Convert::Units::Base;
+require 5.004;
+require Exporter;
+
+@ISA = qw(Exporter);
+
+use vars qw($VERSION);
+
+use Carp;
+
+$VERSION = "0.43";
+
+sub initialize {
+    my $self = shift;
+    $self->{default}   = undef;        # default unit
+    $self->{conversions}       = {};           # conversions
+    $self->{synonyms}  = {};           # unit synonyms and abbreviations
+    $self->{multipliers}       = {};           # multipliers
+}
+
+sub import {
+    my $self = shift;
+
+    my ($conversions, $synonyms, $multipliers, $default) = (@_);
+
+    $self->{conversions}       = $conversions;
+    $self->{synonyms}          = $synonyms;
+    $self->{multipliers}       = $multipliers;
+    $self->{default}           = $default;
+
+    # if no default unit has been defined, look for any "base" unit
+
+    unless (defined($self->{default}))
+    {
+        foreach (keys %{$self->{conversions}})
+        {
+            if (${$self->{conversions}}{$_}==1)
+            {
+                $self->{default} = $_;
+            }
+        }
+    }
+
+    # Add plural versions of unit names
+
+    foreach (keys %{$self->{conversions}}) {
+        ${$self->{conversions}}{$self->plural($_)} = 
${$self->{conversions}}{$_};
+    }
+
+    foreach (keys %{$self->{multipliers}}) {
+        ${$self->{multipliers}}{$self->plural($_)} = 
${$self->{multipliers}}{$_};
+    }
+
+    # Add synonyms and abbreviations for units
+
+    foreach (keys %{$self->{synonyms}}) {
+        ${$self->{conversions}}{$_} = 
${$self->{conversions}}{${$self->{synonyms}}{$_}};
+    }
+}
+
+sub new {
+    my $this = shift;
+    my $class = ref($this) || $this;
+    my $self = {};
+    bless $self, $class;
+    $self->initialize();
+    $self->import(@_);
+    return $self;
+}
+
+# In the future use Lingua::EN::Inflect?
+
+sub plural
+{
+    my $self = shift;
+
+    local ($_) = shift;
+
+    my $suff = "s";
+    
+    $suff = "es",       if (m/(ch|s)$/);
+    $suff = "ies", if (m/y$/);
+
+    $_ .= $suff;
+
+    $_ = "halves", if ($_ eq "halfs"); # exceptions
+    $_ = "feet",   if ($_ eq "foots");
+
+    return $_;
+}
+
+sub parse_unit
+{
+    my $self = shift;
+
+    local ($_) = shift;
+    my $base = shift;  # assume no number specfied = base (0 or 1 usually)
+
+    m/^(\-?\d*(\.\d+)?)\s*(\D*)$/;
+
+    my $number = $1 || $base;
+    my $unit   = $3 || $self->{default};
+
+    unless (defined(${$self->{conversions}}{$unit}))
+    {
+        if ($unit =~ m/(\w+)([\s\-]of[\s\-]an?|[\s\-]of)?[\s\-](\w+)$/)
+        {
+            $number *= ${$self->{multipliers}}{$1};
+            $unit = $3;
+        }
+    }
+
+    unless (defined(${$self->{conversions}}{$unit}))
+    {
+        croak "Invalid unit: $unit";
+    }
+
+    return ($number, $unit);
+}
+
+sub convert_units
+{
+    my $self = shift;
+
+    my ($amount, $unit)        = $self->parse_unit (shift, 0);
+    my ($multiple, $unit_to)   = $self->parse_unit (shift, 1);
+   
+    unless (defined($unit_to)) {
+        $unit_to = $self->{default};
+    }
+
+    my ($M, $A);
+    my $U = ${$self->{conversions}}{$unit};
+
+    if (ref($U) eq ARRAY) {
+        ($M, $A) = @{$U};
+    } else {
+        $M = $U;
+        $A = 0;
+    }
+
+    my $def_unit       = ($amount + $A) * $M;
+
+    $U = ${$self->{conversions}}{$unit_to};
+    if (ref($U) eq ARRAY) {
+        ($M, $A) = @{$U};
+    } else {
+        $M = $U;
+        $A = 0;
+    }
+
+    my $result         = (($def_unit / $M) - $A) / $multiple;
+
+    return $result;
+}
+
+sub parse_string
+{
+    my $self = shift;
+    my $str = lc(shift);
+    my $unit_to = lc(shift);
+
+    my $sum = 0, $el = "1";
+
+    my @units = (split /,|\s+/, $str);
+
+    foreach my $unit (@units) {
+
+        $el = $unit, if ($unit =~ m/^\d/);
+        $el .= " ".$unit, if (($unit =~ m/^\D/) and ($unit !~ m/^(and)$/));
+
+        if ($el =~ m/\d\D/) {
+            $sum += $self->convert_units ($el, $unit_to);
+            $el = "1";
+        }
+    }
+
+    return $sum;
+}
+
+
+1;
+
+__END__
+
+=head1 NAME
+
+Convert::Units::Base - base object for performing unit conversions
+
+=head1 DESCRIPTION
+
+The Units package is a collection of modules for parsing strings with
+unit measurements (such as "12pt" or "3 meters") and converting them
+to some other unit (such as "picas" or "inches").
+
+It uses a base package (Units::Base) which does the dirty work. Other
+modules define what units they handle and how they are related.
+
+=head2 Why a Separate Module?
+
+It is I<intentionally> distinct from the I<Math::Units> module. Why? The
+I<Math::Units> module implies that unit conversions are I<exact>,
+with one-to-one relationships.  This is fine for scientific work.
+It's even fine for some general purpose/real-world uses (such as
+converting Fehrenheight to Celcius).
+
+Real-world measurement systems are conflicting. For instance, a "point"
+in typography is equivalent to 1/72 inch, according to PostScript specs
+and common usage. Other type systems consider it 1/72.27 inch, or 0.01383
+inches, or 0.0148 inches.  Outside of that context, a point may be 1/120
+or 1/144 inch.
+
+Common notations and abbreviations also depend on context. Does "12 pt"
+mean "12 point", "12 parts" or "12 pints"?
+
+Even without conflicts in the definition of a particular unit, there's no
+need to convert point sizes for fonts into miles or light-years. Typesetters,
+surveyors and astronomers user different scales as well as systems.
+
+=head2 People do not think like computers
+
+Not everyone uses the metric system.
+
+And even less people say things like "5.25 feet". Often it's "5 feet, 3 inches"
+or "5 1/4 feet".
+
+Despite having ten fingers and toes, people don't think in tens. They think in
+twos, threes, fours, twelves, and sixteens. And sometimes they use fractional
+measurements like quarter-inches, sixteenths-of-an-inch, or half-pints.
+
+The purpose of this module is to allow people to use the measurement
+systems they are familiar with, and that is appropriate to what they
+are doing.
+
+=head2 Rationale
+
+The Units:: hierarchy is an attempt to keep measurement systems in
+distinct classes. Thus one can have modules for converting between
+typography units (points, picas) distinct from common units of length
+(or area, temperature, etc.), specialized units (for Astronomy, Chemistry,
+Physics, Textiles, Winery, Navigation, etc.) or even traditional or
+regional systems (Japanese, Chinese, Egyptian, archaic systems, etc.)
+and to keep conflicting measurement systems distinct.
+
+=head2 Release Notes
+
+The current distribution contains the following packages:
+
+    Convert::Units::
+    ::Base         - a base module that does all of the work
+    ::Length       - a module for converting units of length
+    ::Temperature  - a module for converting units of temperature
+    ::Type         - a module for converting units of type
+
+Units::Base by itself does nothing. Another module needs to use it
+to create definitions of what units of measurement it handles and
+how they are related to each other (ie, 1 m = 100 cm).
+
+The base unit also allows for synonym and abbreviations to be
+defined.
+
+It also allows common "multiples" to be defined, so that it can
+handle things like "18 half-points" or "6 dozen feet" or even
+convert millimters to "sixteenths of an inch". (It does not yet
+handle Greek prefixes like centi- or mega- ... those will have
+to be manually defined.)
+
+=head2 Known Issues
+
+The current release should be considered "beta" until further testing
+and refinements have been made. Then again, maybe "alpha" is more
+accurate.
+
+The current version does not yet handle fractions such as "1/2 in".
+It should handle decimals such as "0.5 in".
+
+Relationships have been rewritten to be handle A(x+b) as well Ax.
+They may be redone in the future to handle more complex
+relationships, if the need arises.
+
+Unit names much be defined as all lowercase, since strings are
+munged with I<lc()> before processing. In other words, if you define
+a unit name as "F" or "Fahrenheight" you won't be able to use it.
+
+=head2 Future Enhancements
+
+Aside from bug fixes, optimizations, and making the string parsing
+conform more to the "manifesto" above, obvious additions would be modules
+for converting between units of area, volume, weight... (although if
+I<Math::Units> does what you need, use that instead.)
+
+An example hierarchy for future modules:
+
+    Convert::Units::
+    ::Length           - general measures of length
+    ::Area
+    ::Pressure
+    ::Volume
+
+    Convert::Units::Length
+    ::Chinese          - specialized regional/traditional systems
+    ::English
+
+    Convert::Units::Astronomy
+    ::Length           - or Distance...?
+
+Modules should share a common unit (preferably metric) to allow for
+conversions.
+
+=head1 REQUIRED MODULES
+
+    Carp
+
+=head1 SEE ALSO
+
+I<Units::Length>, I<Units::Temperature> and I<Units::Type> modules, which
+demonstrate how I<Units::Base> is used.
+
+=head1 AUTHOR
+
+Robert Rothenberg <wlkng...@unix.asb.com>
+
+=head1 LICENSE
+
+Copyright (c) 1999-2000 Robert Rothenberg. All rights reserved.
+This program is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+
+=cut
diff --git a/Changes b/Changes
new file mode 100644
index 0000000..dd9f838
--- /dev/null
+++ b/Changes
@@ -0,0 +1,19 @@
+Revision history for Perl extension Convert::Units package.
+
+Note that very important changes which affect compatability with previous
+versions are marked with an asterisk ('*').
+
+0.43  Sat Jan 15 22:11:30 2000
+      - cleaned up sloppy syntax to remove warnings
+      - fixed bug with reference to default unit in Base.pm
+
+0.42  Wed Sep 22 23:18:56 1999
+      - fixed bug in Makefile.pl - install was to wrong place
+
+0.41  Tue Sep 21 16:44:06 1999
+      * renamed module to Convert::Units
+      - updated README to current version (oops)
+
+0.40  Sun Sep 12 18:10:03 1999
+      - added ability to use A(x+B) conversions as well as Ax to Units::Base
+      - added Units::Temperature module to demo A(x+B) conversions
diff --git a/Length.pm b/Length.pm
new file mode 100644
index 0000000..4477c64
--- /dev/null
+++ b/Length.pm
@@ -0,0 +1,81 @@
+package Convert::Units::Length;
+require 5.004;
+require Exporter;
+
+use vars qw($VERSION $self);
+$VERSION = "0.14";
+
+use Convert::Units::Base;
+
+my $self = new Convert::Units::Base
+  (
+# The actual units, relative to each other (in this case, in inches)
+    {
+       'centimeter'    => 0.3937,
+        'decameter'    => 393.7,
+        'decimeter'    => 3.937,
+             'foot'    => 12,
+       'hectometer'    => 3937,
+             'inch'    => 1,
+        'kilometer'    => 39370,
+            'meter'    => 39.37,
+       'micrometer'    => 0.00003937,
+             'mile'    => 63360,
+       'millimeter' => 0.03937,
+             'yard' => 36
+    },
+# Synonyms and abbreviations for these units
+    {
+                'm'    => 'meter',
+               'cm'    => 'centimeter',
+               'dm'    => 'decimeter',
+               'km'    => 'kilometer',
+               'mm'    => 'millimeter',
+           'micron'    => 'micrometer',
+               'mi'    => 'mile',
+               'ft'    => 'foot',
+             "\'" => 'foot',
+               'in'    => 'inch',
+               "\"" => 'inch',
+               'yd'    => 'yard',
+                'y'    => 'yard'
+    },
+# Mulipliers (so we can say "dozen inches" or "sixteenths of an inch")
+    {
+            'dozen'       => 12,
+        'quadruple'    => 4,
+           'triple'    => 3,
+           'double'    => 2,
+            'whole'    => 1,
+             'half'    => 1/2,
+            'third'    => 1/3,
+          'quarter'    => 1/4,
+           'eighth'    => 1/8,
+           'twelth'    => 1/12,
+        'sixteenth'    => 1/16,
+            'tenth'    => 1/10,
+        'twentieth'    => 1/20,
+         'fiftieth'    => 1/50,
+         'hundreth'    => 1/100,
+           'single'    => 1
+    },
+# The default unit to convert to (when none is specified)
+    "inch"
+);
+
+
+# A stub for converting units
+sub convert
+{
+    return $self->convert_units (@_);
+}
+
+# A stub for parsing strings (such as "1 foot, 3 inches")
+sub parse
+{
+    return $self->parse_string (@_);
+}
+
+1;
+
+__END__
diff --git a/MANIFEST b/MANIFEST
new file mode 100644
index 0000000..988b8ed
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,11 @@
+Base.pm
+Changes
+Length.pm
+Makefile.PL
+MANIFEST
+README
+Temperature.pm
+test.pl
+Type.pm
+
+
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644
index 0000000..141d0e2
--- /dev/null
+++ b/Makefile.PL
@@ -0,0 +1,14 @@
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    'PM' => {
+       'Base.pm' => '$(INST_LIBDIR)/Units/Base.pm',
+       'Length.pm' => '$(INST_LIBDIR)/Units/Length.pm',  
+       'Temperature.pm' => '$(INST_LIBDIR)/Units/Temperature.pm',
+       'Type.pm' => '$(INST_LIBDIR)/Units/Type.pm'  
+     },
+    'DISTNAME' => 'Convert-Units',
+    'NAME'     => 'Convert::Units',
+    'VERSION_FROM' => 'Base.pm'
+);
+
diff --git a/README b/README
new file mode 100644
index 0000000..f2768e2
--- /dev/null
+++ b/README
@@ -0,0 +1,157 @@
+NAME
+
+    Convert::Units::Base - base object for performing unit
+    conversions
+
+CHANGES SINCE LAST RELEASE
+
+    0.43  Sat Jan 15 22:11:30 2000
+          - cleaned up sloppy syntax to remove warnings
+          - fixed bug with reference to default unit in Base.pm
+
+DESCRIPTION
+
+    The Units package is a collection of modules for parsing strings
+    with unit measurements (such as "12pt" or "3 meters") and
+    converting them to some other unit (such as "picas" or
+    "inches").
+
+    It uses a base package (Units::Base) which does the dirty work.
+    Other modules define what units they handle and how they are
+    related.
+
+  Why a Separate Module?
+
+    It is *intentionally* distinct from the *Math::Units* module.
+    Why? The *Math::Units* module implies that unit conversions are
+    *exact*, with one-to-one relationships. This is fine for
+    scientific work. It's even fine for some general purpose/real-
+    world uses (such as converting Fehrenheight to Celcius).
+
+    Real-world measurement systems are conflicting. For instance, a
+    "point" in typography is equivalent to 1/72 inch, according to
+    PostScript specs and common usage. Other type systems consider
+    it 1/72.27 inch, or 0.01383 inches, or 0.0148 inches. Outside of
+    that context, a point may be 1/120 or 1/144 inch.
+
+    Common notations and abbreviations also depend on context. Does
+    "12 pt" mean "12 point", "12 parts" or "12 pints"?
+
+    Even without conflicts in the definition of a particular unit,
+    there's no need to convert point sizes for fonts into miles or
+    light-years. Typesetters, surveyors and astronomers user
+    different scales as well as systems.
+
+  People do not think like computers
+
+    Not everyone uses the metric system.
+
+    And even less people say things like "5.25 feet". Often it's "5
+    feet, 3 inches" or "5 1/4 feet".
+
+    Despite having ten fingers and toes, people don't think in tens.
+    They think in twos, threes, fours, twelves, and sixteens. And
+    sometimes they use fractional measurements like quarter-inches,
+    sixteenths-of-an-inch, or half-pints.
+
+    The purpose of this module is to allow people to use the
+    measurement systems they are familiar with, and that is
+    appropriate to what they are doing.
+
+  Rationale
+
+    The Units:: hierarchy is an attempt to keep measurement systems
+    in distinct classes. Thus one can have modules for converting
+    between typography units (points, picas) distinct from common
+    units of length (or area, temperature, etc.), specialized units
+    (for Astronomy, Chemistry, Physics, Textiles, Winery,
+    Navigation, etc.) or even traditional or regional systems
+    (Japanese, Chinese, Egyptian, archaic systems, etc.) and to keep
+    conflicting measurement systems distinct.
+
+  Release Notes
+
+    The current distribution contains the following packages:
+
+        Convert::Units::
+        ::Base         - a base module that does all of the work
+        ::Length       - a module for converting units of length
+        ::Temperature  - a module for converting units of temperature
+        ::Type         - a module for converting units of type
+
+    Units::Base by itself does nothing. Another module needs to use
+    it to create definitions of what units of measurement it handles
+    and how they are related to each other (ie, 1 m = 100 cm).
+
+    The base unit also allows for synonym and abbreviations to be
+    defined.
+
+    It also allows common "multiples" to be defined, so that it can
+    handle things like "18 half-points" or "6 dozen feet" or even
+    convert millimters to "sixteenths of an inch". (It does not yet
+    handle Greek prefixes like centi- or mega- ... those will have
+    to be manually defined.)
+
+  Known Issues
+
+    The current release should be considered "beta" until further
+    testing and refinements have been made. Then again, maybe
+    "alpha" is more accurate.
+
+    The current version does not yet handle fractions such as "1/2
+    in". It should handle decimals such as "0.5 in".
+
+    Relationships have been rewritten to be handle A(x+b) as well
+    Ax. They may be redone in the future to handle more complex
+    relationships, if the need arises.
+
+    Unit names much be defined as all lowercase, since strings are
+    munged with *lc()* before processing. In other words, if you
+    define a unit name as "F" or "Fahrenheight" you won't be able to
+    use it.
+
+  Future Enhancements
+
+    Aside from bug fixes, optimizations, and making the string
+    parsing conform more to the "manifesto" above, obvious additions
+    would be modules for converting between units of area, volume,
+    weight... (although if *Math::Units* does what you need, use
+    that instead.)
+
+    An example hierarchy for future modules:
+
+        Convert::Units::
+        ::Length            - general measures of length
+        ::Area
+        ::Pressure
+        ::Volume
+
+        Convert::Units::Length
+        ::Chinese           - specialized regional/traditional systems
+        ::English
+
+        Convert::Units::Astronomy
+        ::Length            - or Distance...?
+
+    Modules should share a common unit (preferably metric) to allow
+    for conversions.
+
+REQUIRED MODULES
+
+        Carp
+
+SEE ALSO
+
+    *Units::Length*, *Units::Temperature* and *Units::Type* modules,
+    which demonstrate how *Units::Base* is used.
+
+AUTHOR
+
+    Robert Rothenberg <wlkng...@unix.asb.com>
+
+LICENSE
+
+    Copyright (c) 1999 Robert Rothenberg. All rights reserved. This
+    program is free software; you can redistribute it and/or modify
+    it under the same terms as Perl itself.
+
diff --git a/Temperature.pm b/Temperature.pm
new file mode 100644
index 0000000..fd1667b
--- /dev/null
+++ b/Temperature.pm
@@ -0,0 +1,46 @@
+package Convert::Units::Temperature;
+require 5.004;
+require Exporter;
+
+use vars qw($VERSION $self);
+$VERSION = "0.21";
+
+use Convert::Units::Base;
+
+my $self = new Convert::Units::Base
+  (
+# The actual units, relative to each other (in this case, in inches)
+    {
+          'celsius' => [1.0,    0],
+     'fahrenheight' => [5/9,  -32],
+           'kelvin' => [1.0, -273]
+    },
+# Synonyms and abbreviations for these units
+    {
+       'centigrade' => 'celsius',
+                'c' => 'celsius',
+                'f' => 'fahrenheight',
+                'k' => 'kelvin'
+    },
+# Mulipliers
+    (),
+# The default unit to convert to (when none is specified)
+    "celsius"
+);
+
+# A stub for converting units
+sub convert
+{
+    return $self->convert_units (@_);
+}
+
+# A stub for parsing strings (such as "1 foot, 3 inches")
+sub parse
+{
+    return $self->parse_string (@_);
+}
+
+1;
+
+__END__
+
diff --git a/Type.pm b/Type.pm
new file mode 100644
index 0000000..ca45634
--- /dev/null
+++ b/Type.pm
@@ -0,0 +1,56 @@
+package Convert::Units::Type;
+require 5.004;
+require Exporter;
+
+use vars qw($VERSION $self);
+$VERSION = "0.34";
+
+use Convert::Units::Base;
+
+my $self = new Convert::Units::Base
+  (
+# The actual units, relative to each other (in this case, in inches)
+    {
+             'inch'    => 1,
+             'pica'    => 1/6, # PostScript (Anglo/Am 0.166in)
+            'point' => 1/72,   # PostScript (Anglo/Am 0.01383in, Europe 
0.0148in. 72.27pts/in??)
+             'twip'    => 1/1440,
+       'centimeter'    => 0.3937,
+       'millimeter' => 0.03937
+    },
+# Synonyms and abbreviations for these units
+    {
+               'cm'    => 'centimeter',
+               'mm'    => 'millimeter',
+               'in'    => 'inch',
+               'pt'    => 'point',
+               'pc'    => 'pica'
+    },
+# Mulipliers (so we can say "half-pica" or "sixteenths of an inch")
+    {
+             'half'    => 1/2,
+            'third'    => 1/3,
+          'quarter'    => 1/4,
+           'eighth'    => 1/8,
+           'twelth'    => 1/12,
+        'sixteenth'    => 1/16
+    },
+# The default unit to convert to (when none is specified)
+    "point"
+);
+
+# A stub for converting units
+sub convert
+{
+    return $self->convert_units (@_);
+}
+
+# A stub for parsing strings (such as "1 foot, 3 inches")
+sub parse
+{
+    return $self->parse_string (@_);
+}
+
+1;
+
+__END__
diff --git a/test.pl b/test.pl
new file mode 100644
index 0000000..3ee11e1
--- /dev/null
+++ b/test.pl
@@ -0,0 +1,20 @@
+# Before `make install' is performed this script should be runnable with
+# `make test'. After `make install' it should work as `perl test.pl'
+
+######################### We start with some black magic to print on failure.
+
+# Change 1..1 below to 1..last_test_to_print .
+# (It may become useful if the test is moved to ./t subdirectory.)
+
+BEGIN { $| = 1; print "1..1\n"; }
+END {print "not ok 1\n" unless $loaded;}
+use Convert::Units::Length;
+use Convert::Units::Type;
+use Convert::Units::Temperature;
+$loaded = 1;
+print "ok 1\n";
+
+######################### End of black magic.
+
+# We need a better test here
+

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-perl/packages/libconvert-units-perl.git

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to