Data-Miscellany
view release on metacpan or search on metacpan
lib/Data/Miscellany.pm view on Meta::CPAN
C<is_defined()> method.
This subroutine checks whether its argument is a value object and if so, calls
the value object's C<is_defined()> method. Otherwise, the normal C<defined()>
is used.
=head2 value_of(SCALAR)
Stringifies its argument, but returns undefined values (per C<is_defined()>)
as C<undef>.
=head2 str_value_of(SCALAR)
Stringifies its argument, but returns undefined values (per C<is_defined()>)
as the empty string.
=head2 class_map(SCALAR, HASH)
Takes an object or class name as the first argument (if it's an object, the
class name used will be the package name the object is blessed into).
Takes a hash whose keys are class names as the second argument. The hash
values are completely arbitrary.
Looks up the given class name in the hash and returns the corresponding value.
If no such hash key is found, the class hierarchy for the given class name is
traversed depth-first and checked against the hash keys in turn. The first
value found is returned.
If no key is found, a special key, C<UNIVERSAL> is used.
As an example of how this might be used, consider a hierarchy of exception
classes. When evaluating each exception, we want to know how severe this
exception is, so we define constants for C<RC_OK> (meaning it's informational
only), C<RC_ERROR> (meaning some sort of action should be taken) and
C<RC_INTERNAL_ERROR> (meaning something has gone badly wrong and we might halt
processing). In the following table assume that if you have names like
C<Foo::Bar> and C<Foo::Bar::Baz>, then the latter subclasses the former.
%map = (
'UNIVERSAL' => RC_INTERNAL_ERROR,
'My::Exception::Business' => RC_ERROR,
'My::Exception::Internal' => RC_INTERNAL_ERROR,
'My::Exception::Business::ValueNormalized' => RC_OK,
);
Assuming that C<My::Exception::Business::IllegalValue> exists and that it
subclasses C<My::Exception::Business>, here are some outcomes:
class_map('My::Exception::Business::IllegalValue', \%map) # RC_ERROR
class_map('My::Exception::Business::ValueNormalzed', \%map) # RC_OK
=head2 trim(STRING)
Trims off whitespace at the beginning and end of the string and returns the
trimmed string.
=head1 INSTALLATION
See perlmodinstall for information and options on installing Perl modules.
=head1 BUGS AND LIMITATIONS
No bugs have been reported.
Please report any bugs or feature requests through the web interface at
L<http://rt.cpan.org/Public/Dist/Display.html?Name=Data-Miscellany>.
=head1 AVAILABILITY
The latest version of this module is available from the Comprehensive Perl
Archive Network (CPAN). Visit L<http://www.perl.com/CPAN/> to find a CPAN
site near you, or see
L<http://search.cpan.org/dist/Data-Miscellany/>.
The development version lives at
L<http://github.com/hanekomu/Data-Miscellany/>.
Instead of sending patches, please fork this project using the standard git
and github infrastructure.
=head1 AUTHOR
Marcel Gruenauer <marcel@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2004 by Marcel Gruenauer.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
( run in 2.008 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )