NAME
Astro::App::Satpass2::Utils - Utilities for Astro::App::Satpass2
SYNOPSIS
use Astro::App::Satpass2::Utils qw{ instance };
instance( $foo, 'Bar' )
or die '$foo is not an instance of Bar';
DESCRIPTION
This module is a grab-bag of utilities needed by Astro::App::Satpass2.
This module is private to the Astro::App::Satpass2 package. Any and all functions in it can be modified or revoked without prior notice. The documentation is for the convenience of the author.
All documented subroutines can be exported, but none are exported by default.
SUBROUTINES
This module supports the following exportable subroutines:
has_method
has_method( $object, $method );
This exportable subroutine returns a code reference to the named method if the given object has the method, or a false value otherwise. What you actually get is the result of $invocant->can( $method )
if the invocant is a blessed reference, or a return otherwise.
instance
instance( $object, $class )
This exportable subroutine returns a true value if $object
is an instance of $class
, and false otherwise. The $object
argument need not be a reference, nor need it be blessed, though in these cases the return is false.
load_package
load_package( $module );
load_package( $module, 'Astro::App::Satpass2' );
This exportable subroutine loads a Perl module. The first argument is the name of the module itself. Subsequent arguments are prefixes to try, without any trailing colons.
In the examples, if $module
contains 'Foo'
, the first example will try to require 'Foo'
, and the second will try to require 'Astro::App::Satpass2::Foo'
and require 'Foo'
, in that order. The first attempt that succeeds returns the name of the module actually loaded. If no attempt succeeds, undef
is returned.
Arguments are cached, and subsequent attempts to load a module simply return the contents of the cache.
merge_hashes
my $hash_ref = merge_hashes( \%hash1, \%hash2, ... );
This subroutine returns a reference to a hash that contains keys merged from all the hash references passed as arguments. Arguments which are not hash references are removed before processing. If there are no arguments, an empty hash is returned. If there is exactly one argument, it is returned. If there is more than one argument, a new hash is constructed from all keys of all hashes, and that hash is returned. If the same key appears in more than one argument, the value from the right-most argument is the one returned.
my_dist_config
my $cfg_dir = my_dist_config( { 'create-directory' => 1 } );
This subroutine simply wraps
File::HomeDir->my_dist_config( 'Astro-App-Satpass2' );
You can pass an optional reference to an options hash (sic!). The only supported option is {'create-directory'}, which is passed verbatim to the File::HomeDir
'create'
option.
If the configuration directory is found or successfully created, the path to it is returned. Otherwise undef
is returned.
quoter
quoter( $string )
This exportable subroutine quotes and escapes its argument as necessary for the parser. Specifically, if $string
is:
* undef, 'undef'
is returned;
* a number, $string
is returned unmodified;
* an empty string, ''
is returned;
* a string containing white space, quotes, or dollar signs, the value is escaped and enclosed in double quotes (""
).
* anything else is returned unmodified.
SUPPORT
Support is by the author. Please file bug reports at http://rt.cpan.org, or in electronic mail to the author.
AUTHOR
Thomas R. Wyant, III wyant at cpan dot org
COPYRIGHT AND LICENSE
Copyright (C) 2011-2013 by Thomas R. Wyant, III
This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For more details, see the full text of the licenses in the directory LICENSES.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.