Error-Hierarchy
view release on metacpan or search on metacpan
lib/Error/Hierarchy/Util.pm view on Meta::CPAN
=head2 assert_named_args(\%args, @args_spec)
This function helps in validating named arguments passed to a method or
function. The first argument is a reference to the hash of named arguments,
the remaining arguments define which argument names are allowed. If an
argument name starts with a C<+> sign, it means that this argument is
mandatory.
For example, assume your method only accepts the keys C<foo>, C<bar> and
C<baz>, and C<bar> is mandatory. Usually you will write your method like this:
sub my_method {
my ($self, %args) = @_;
assert_named_args(\%args, qw(foo +bar baz));
# ...
}
If there was a validation error, an exception of type
L<Error::Hierarchy::Internal::CustomMessage> will be thrown with details about
what went wrong.
=head2 assert_enum()
Takes a value and a reference to an array of valid values - that is, the
enumeration. If the value is not among the enumerated valid values, an
exception is thrown.
=head2 loader_callback($coderef)
Support for "virtual" classes that do not exist as files. It is used in
C<load_class()>, so see its documentation.
=head2 load_class($class, $verbose))
load_class 'Some::Class', 1;
Takes as arguments a package name and a boolean verbosity flag. Tries to load
the package and if it can't be loaded, it throws a
L<Error::Hierarchy::Internal::CustomMessage> exception with the error message
obtained when trying to load the package.
To save time, this function checks whether the package defines a C<$VERSION>
and if so, it assumes that the package has already been loaded and returns
right away.
If the class can't be loaded via C<require()> but we have a
C<loader_callback()>, it is invoked with the class name.
If the verbose flag is set, the error code - C<$@> - is printed immediately if
a problem occurs. You might want to set this flag in when testing your code to
get a quick feedback on loading problems, but you should have a graceful
method to deal with the problem anyway.
This function is called C<load_class()> and not C<load_package()> for
historical reasons.
=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=Error-Hierarchy>.
=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/Error-Hierarchy/>.
The development version lives at L<http://github.com/hanekomu/Error-Hierarchy>
and may be cloned from L<git://github.com/hanekomu/Error-Hierarchy>.
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 1.293 second using v1.01-cache-2.11-cpan-39bf76dae61 )