home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / exports.pm < prev    next >
Encoding:
Perl POD Document  |  2001-12-16  |  2.2 KB  |  112 lines

  1. package UNIVERSAL::exports;
  2. $UNIVERSAL::exports::VERSION = '0.03';
  3.  
  4.  
  5. package UNIVERSAL;
  6. use Exporter::Lite qw(import);
  7.  
  8. =head1 NAME
  9.  
  10. UNIVERSAL::exports - Lightweight, universal exporting of variables
  11.  
  12. =head1 SYNOPSIS
  13.  
  14.   package Foo;
  15.   use UNIVERSAL::exports;
  16.  
  17.   # Just like Exporter.
  18.   @EXPORT       = qw($This &That);
  19.   @EXPORT_OK    = qw(@Left %Right);
  20.  
  21.  
  22.   # Meanwhile, in another piece of code!
  23.   package Bar;
  24.   use Foo;  # exports $This and &That.
  25.  
  26.  
  27. =head1 DESCRIPTION
  28.  
  29. This is an alternative to Exporter intended to provide a universal,
  30. lightweight subset of its functionality.  It uses Exporter::Lite, so
  31. look there for details.
  32.  
  33. Additionally, C<exports()> is provided to find out what symbols a
  34. module exports.
  35.  
  36. UNIVERSAL::exports places its methods in the UNIVERSAL namespace, so
  37. there is no need to subclass from it.
  38.  
  39.  
  40. =head1 Methods
  41.  
  42. UNIVERSAL::exports has two public methods, import() derived from
  43. Exporter::Lite, and exports().
  44.  
  45. =over 4
  46.  
  47. =item B<import>
  48.  
  49.   Some::Module->import;
  50.   Some::Module->import(@symbols);
  51.  
  52. This is Exporter::Lite's import() method.  Look in L<Exporter::Lite>
  53. for details.
  54.  
  55. =item B<exports>
  56.  
  57.   @exported_symbols = Some::Module->exports;
  58.   Some::Module->exports($symbol);
  59.  
  60. Reports what symbols are exported by Some::Module.  With no arguments,
  61. it simply returns a list of all exportable symbols.  Otherwise, it
  62. reports if it will export a given $symbol.
  63.  
  64. =cut
  65.  
  66.  
  67. sub exports {
  68.     my($exporter) = shift;
  69.  
  70.     my %exports = map { $_ => 1 } @{$exporter.'::EXPORT'}, 
  71.                                   @{$exporter.'::EXPORT_OK'};
  72.  
  73.     if( @_ ) {
  74.         return exists $exports{$_[0]};
  75.     }
  76.     else {
  77.         return keys %exports;
  78.     }
  79. }
  80.  
  81.  
  82. =back
  83.  
  84. =head1 DIAGNOSTICS
  85.  
  86. =over 4
  87.  
  88. =item '"%s" is not exported by the %s module'
  89.  
  90. Attempted to import a symbol which is not in @EXPORT or @EXPORT_OK.
  91.  
  92. =item 'Can\'t export symbol: %s'
  93.  
  94. Attempted to import a symbol of an unknown type (ie. the leading $@% salad
  95. wasn't recognized).
  96.  
  97. =back
  98.  
  99.  
  100. =head1 AUTHORS
  101.  
  102. Michael G Schwern <schwern@pobox.com>
  103.  
  104. =head1 SEE ALSO
  105.  
  106. L<Exporter>, L<UNIVERSAL::require>, http://dev.perl.org/rfc/257.pod
  107.  
  108. =cut
  109.  
  110.  
  111. 007;
  112.