Skip to content

Commit

Permalink
Another commit caused by git noobness.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluefeet committed Jun 24, 2009
1 parent dc408ad commit f72a839
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 211 deletions.
5 changes: 5 additions & 0 deletions Changes
@@ -1,5 +1,10 @@
Revision history for Perl extension Class::Measure.

0.04
- Fix tests to declare the number of test first and to not use lib.
- Remove AUTOLOAD. Slap me please.
- Other random cleanups.

0.03
- Added nautical_mile length unit type.

Expand Down
16 changes: 12 additions & 4 deletions MANIFEST
@@ -1,9 +1,17 @@
Changes
MANIFEST
README
Build.PL
META.yml
inc/Module/Install.pm
inc/Module/Install/Base.pm
inc/Module/Install/Can.pm
inc/Module/Install/Fetch.pm
inc/Module/Install/Makefile.pm
inc/Module/Install/Metadata.pm
inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
lib/Class/Measure.pm
lib/Class/Measure/Length.pm
Makefile.PL
MANIFEST This list of files
META.yml
README
t/00_measure.t
t/01_length.t
3 changes: 3 additions & 0 deletions META.yml
Expand Up @@ -4,6 +4,7 @@ author:
- 'Aran Clary Deltac <bluefeet@cpan.org>'
build_requires:
ExtUtils::MakeMaker: 6.42
Test::More: 0.82
configure_requires:
ExtUtils::MakeMaker: 6.42
distribution_type: module
Expand All @@ -17,6 +18,8 @@ no_index:
directory:
- inc
- t
requires:
Sub::Exporter: 0.982
resources:
license: http://dev.perl.org/licenses/
version: 0.04
3 changes: 3 additions & 0 deletions Makefile.PL
Expand Up @@ -3,4 +3,7 @@ use inc::Module::Install;
name 'Class-Measure';
all_from 'lib/Class/Measure.pm';

requires 'Sub::Exporter' => '0.982';
test_requires 'Test::More' => '0.82';

WriteAll;
111 changes: 109 additions & 2 deletions README
@@ -1,4 +1,111 @@
Class::Measure 0.03
NAME
Class::Measure - Create, compare, and convert units of measurement.

See: http://www.arandeltac.com/ClassMeasureModule
SYNOPSIS
See Class::Measure::Length for some examples.

DESCRIPTION
This is a base class that is inherited by the Class::Measure classes.
This distribution comes with the class Class::Measure::Length.

The classes Class::Measure::Area, Class::Measure::Mass,
Class::Measure::Space, Class::Measure::Temperature, and
Class::Measure::Volume are planned and will be added soon.

The methods described here are available in all Class::Measure classes.

METHODS
new
my $m = new Class::Measure::Length( 1, 'inch' );

Creates a new measurement object. You must pass an initial measurement
and default unit.

In most cases the measurement class that you are useing will export a
method to create new measurements. For example Class::Measure::Length
exports the length() method.

unit
my $unit = $m->unit;

Returns the object's default unit.

set_unit
$m->set_unit( 'feet' );

Sets the default unit of the measurement.

value
my $yards = $m->value('yards');
my $val = $m->value;
print "$m is the same as $val when in a string\n";

Retrieves the value of the measurement in the default unit. You may
specify a unit in which case the value is converted to the unit and
returned.

This method is also used to handle overloading of stringifying the
object.

set_value
my $m = length( 0, 'inches' );
$m->set_value( 12 ); # 12 inches.
$m->set_value( 1, 'foot' ); # 1 foot.

Sets the measurement in the default unit. You may specify a new default
unit as well.

reg_units
Class::Measure::Length->reg_units(
'inch', 'foot', 'yard'
);

Registers one or more units for use in the specified class. Units should
be in the singular, most common, form.

units
my @units = Class::Measure::Length->units();

Returns a list of all registered units.

reg_aliases
Class::Measure::Length->reg_aliases(
['feet','ft'] => 'foot',
['in','inches'] => 'inch',
'yards' => 'yard'
);

Register alternate names for units. Expects two arguments per unit to
alias. The first argument being the alias (scalar) or aliases (array
ref), and the second argument being the unit to alias them to.

reg_convs
Class::Measure::Length->reg_convs(
12, 'inches' => 'foot',
'yard' => '3', 'feet'
);

Registers a unit conversion. There are three distinct ways to specify a
new conversion. Each requires three arguments.

$count1, $unit1 => $unit2
$unit1 => $count2, $unit2

These first two syntaxes create automatic reverse conversions as well.
So, saying there are 12 inches in a foot implies that there are 1/12
feet in an inch.

$unit1 => $unit2, $sub

The third syntax accepts a subroutine as the last argument the
subroutine will be called with the value of $unit1 and it's return value
will be assigned to $unit2. This third syntax does not create a reverse
conversion automatically.

AUTHOR
Aran Clary Deltac <bluefeet@cpan.org>

LICENSE
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

0 comments on commit f72a839

Please sign in to comment.