first - use the first loadable module in a list


first documentation  | view source Contained in the first distribution.

Index


NAME

Top

first - use the first loadable module in a list

SYNOPSIS

Top

  use first 'YAML::Syck', 'YAML::TINY', 'YAML';

  if( $first::module ) {
      print "Looks like I'll be using $first::module for this YAML..."
  }
  else {
      die "I have no YAML modules: $@";
  }

  my $yaml = $first::module->new();

  use first 'CGI::Simple', 'CGI::Minimal', 'CGI';
  my $cgi = $first::module ? $first::module->new() : $fallback_obj;

DESCRIPTION

Top

Two main circumstances I've encountered where this is useful is:

* when you have a list of modules that have the same interface but are more desirable for one reason or another like speed, portability, or availability.
    use first 'CGI::Simple', 'CGI::Minimal', 'CGI';

* when you have a list of modules that do the same task but via different methods
    use first 'YAML::Syck', 'YAML::TINY', 'YAML', 'XML::Tiny', 'XML::Simple', 'Storable';

    my $serializer = $first::module;

    # now use functions based on $serializer / $first::module, perhaps keeping it in a hash that maps funtions to the name space for a consistent API where none existed before

ARGUMENTS

Top

Arguments after 'use first' can be a name space string or an array reference whose first item is a name space and the rest is what would get passed to/after 'use Name::Space'

VARIABLES

Top

These variables are available after 'use first' and are reset upon each call of 'use first' (Similar to how $@ is reset with every eval)

$first::module

Contains the namespace that was loaded, if any. undefined otherwise if none could be loaded.

$first::failed

Is a hashref whose keys are the name space that could not be loaded and the values are the given key's error message.

$@

Contains the last error, if any.

SEE ALSO

Top

last, any, all, fake

TODO

Top

More tests as per first.t

AUTHOR

Top

Daniel Muey, http://drmuey.com/cpan_contact.pl

COPYRIGHT AND LICENSE

Top


first documentation  | view source Contained in the first distribution.