Name
Object::Relation::Functions - Object::Relation Utility Functions.
Synopsis
use Object::Relation::Functions qw/:uuid/;
my $uuid = create_uuid();
Description
This class is a centralized repository for Object::Relation utility functions.
:uuid
These functions manage UUIDs.
create_uuid()
Generates and returns a version 4 UUID string.
uuid_to_bin
Converts a UUID from its string representation into its binary representation.
uuid_to_hex
Converts a UUID from its string representation into its hex representation.
uuid_to_b64
Converts a UUID from its string representation into its base 64 representation.
:gtin
isa_gtin
print "$gtin is valid\n" if isa_gtin($gtin);
Returns true if GTIN argument is valid, and false if it is not.
The checksum is calculated according to this equation:
Add the digits in the 1s, 100s, 10,000s, etc. positions together and multiply by three.
Add the digits in the 10s, 1,000s, 100,000s, etc. positions to the result.
Return true if the result is evenly divisible by 10, and false if it is not.
See http://www.gs1.org/productssolutions/idkeys/support/check_digit_calculator.html#how for tables describing how GTIN checkdigits are calculated.
Class handling functions
The following functions are generic utilities for handling classes. They can be imported individually or with the :class
tag.
use Object::Relation::Functions ':class';
file_to_mod
my $module = file_to_mod($search_dir, $file);
Converts a file name to a Perl module name. The file name may be an absolute or relative file name ending in .pm. file_to_mod()
will walk through both the $search_dir
directories and the $file
directories and remove matching elements of each from $file
.
load_classes
my $classes = load_classes(@dirs);
my @classes = load_classes(@dirs, $rule);
Uses File::Find::Rule to find and load all Perl modules found in the directories specified and their subdirectories, and returns a list or array reference of the Object::Relation::Meta::Class objects for each that inherits from Object::Relation::Base
and is not abstract. If the last argument so the method is not a File::Find::Rule object, one will be created that ignores directories named .svn and CVS
and loads all files that end in .pm and do not contain "#" in their names. If you need something more strict or lenient, create your own File::Find::Rule object and pass it as the last argument. Use Unix-style directory naming for the directory arguments; load_classes()
will automatically convert the them to the appropriate format for the current operating system.
load_class
my $class = load_class($class, $base_class, $default_class);
Loads the class specified by the $class argument. It first tries to load it as "$base_class::$class". If that class does not exist, it simply loads $class. In the case where $class is undef
, $default_class will be used instead.
Copyright and License
Copyright (c) 2004-2006 Kineticode, Inc. <info@obj_relode.com>
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.