Hub - Hub Library Interface


hub-standard documentation  | view source Contained in the hub-standard distribution.

Index


NAME

Top

Hub - Hub Library Interface

SYNOPSIS

Top

We pollute our symbol table with all of our internal libraries' EXPORT_OK symbols so you don't have to.

    use Hub; # nothing imported
    print 'Why hello there, mister ', Hub::getname($0), "\n";

    use Hub ':standard';
    print 'Excuse me, mister ', getname($0), "\n";

In both cases, Hub::Data::File::getname(...) is the called method.

DESCRIPTION

Top

PUBLIC METHODS

Top

import

Get symbols from this library

This adapter method allows us to look at the requested tags before Exporter gets ahold of it. We want to dynamically load internal libraries based on the requested tag. In this way, you can create a new set of modules:



  /path/to/lib/Hub/Mystuff/Peak.pm
                          /Crescendo.pm




and use them in a file as:



  use Hub(:mystuff);




and you get the same facilities as this library itself. Meaning you can call EXPORT_OK subroutines of Peak.pm and Crescendo.pm as Hub::subroutine() or just subroutine().

Inside Peak.pm and Crescendo.pm, you should:



  use Hub(:lib);




So you get the standard set of external symbols, like import, carp, croak, cluck, confess, blessed, time, gettimeofday, tv_interval and cwd(). See _load_external_libs.

If you would like Crescendo.pm to use methods from Peak.pm, you should:



  use Hub(:lib :mystuff);




And then reference those methods as Hub::methodname(). This is not a requirement by any means, but half of the reasons for doing all this in the first place is to make refactoring simple. If you follow this route (note you should also be using Hub::mkinst('Peak') to create your objects) than you can move code around without changing the API.

mkinst

Create an instance (object) by its short name.





 Usage: mkinst $short_name




See also hubuse.

Example returns: true:

    ref(mkinst('Object')) eq 'Hub::Base::Object';




Example returns: abort:

    mkinst('DoesNotExist');







knot

Return the implementing package (full name) for the given knot


 Usage: knot $short_name




See also hubuse.

callback

Invocation method for persistent applications


 Usage: callback \&subroutine

Intended usage:



  #!/usr/bin/perl -w
  use strict;
  use Hub qw(:standard);
  while( my $req = ??? ) {
      callback( &main, $req );
  }
  sub main {
      my $req = shift;
      # your code here
  }




The callback method wraps your code with the necessary initialization and destruction code required to isolate this instance (run) from others.

regns

Register namespace.





 Usage: regns $name, [\%value]




Intended for Hub library modules only.

getns

Get namespace


 Usage: getns $name, [$address]

Intended for Hub library modules only.

trace

Warn with a stack trace


 Usage: trace @messages




about

Return an about message regarding this library


 Usage: about




version

Return the library version number


 Usage: version




INTERNAL METHODS

Top

_load_external_libs

Load external modules.

Share minimal list of standard functions which every module in its right mind would use.

_load_internal_libs

We want to import all EXPORT_OK methods from packages.





 Usage: _load_internal_libs @list
 Usage: _load_internal_libs 'all'




Where each item in @list is the name of a directory beneath 'Hub'.

_findmodules

Recursively get module names


 Usage: _findmodules $directory, $package_name

Searches in the sub-directory of this top-level-module for all library files to represent. $package_name is the package (directory) name which corresponds to the given $directory.

Recursive.

_tagname

Return which EXPORT_TAGS key to which a module should belong.





 Usage: _tagname $module_name




END

Finish library wheel.

AUTHOR

Top

Ryan Gies (ryangies@livesite.net)

COPYRIGHT

Top

UPDATED

Top

08/02/2007


hub-standard documentation  | view source Contained in the hub-standard distribution.