UNIVER...xports(3pm)

πŸ’– UNIVERSAL::exports πŸ’–

okay so bestie, welcome to UNIVERSAL::exports β€” the lightweight, universal exporting of variables situation. It's a Perl module (a 3pm one, iykyk) and it lives in the User Contributed Perl Documentation corner of your system. Let's get into it ✨


🌸 SYNOPSIS 🌸

  package Foo;
  use UNIVERSAL::exports;

  # Just like Exporter.
  @EXPORT       = qw($This &That);
  @EXPORT_OK    = qw(@Left %Right);

  # Meanwhile, in another piece of code!
  package Bar;
  use Foo;  # exports $This and &That.

like… you set up @EXPORT and @EXPORT_OK exactly the way you already know and love, and then the other package just uses you and gets the goods. periodt. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the tea: this is an alternative to Exporter that's meant to give you a universal, lightweight subset of what Exporter does. It leans on Exporter::Lite, so if you want the deets on how that all works, go look there πŸ‘€.

On top of all that, it also hands you exports() so you can find out what symbols a module exports. Very demure. Very mindful. πŸŽ€

And the iconic part? UNIVERSAL::exports puts its methods in the UNIVERSAL namespace, so there is literally no need to subclass from it. Not me avoiding inheritance πŸ’€.


✨ Methods ✨

UNIVERSAL::exports has two public methods: import() (which is derived from Exporter::Lite) and exports().

🌈 import

      Some::Module->import;
      Some::Module->import(@symbols);

This is Exporter::Lite's import() method, bestie. Look in Exporter::Lite for details. 🫢

🌈 exports

      @exported_symbols = Some::Module->exports;
      Some::Module->exports($symbol);

This one reports what symbols are exported by Some::Module. With no arguments, it just returns a list of all exportable symbols. Otherwise? It reports whether it will export a given $symbol. Very useful, very slay. πŸ’™


πŸ’€ DIAGNOSTICS πŸ’€

  • '"%s" is not exported by the %s module' β€” you tried to import a symbol that is not in @EXPORT or @EXPORT_OK. Rude of you, honestly πŸ™ˆ.
  • 'Can\'t export symbol: %s' β€” you tried to import a symbol of an unknown type, aka the leading $@% salad wasn't recognized πŸ₯—πŸ˜­.

πŸ‘‘ AUTHORS πŸ‘‘

Michael G Schwern <schwern@pobox.com>

an absolute legend, fr fr. ✨


πŸ› BUGS and ISSUES πŸ›

Please report bugs and issues via <http://rt.cpan.org> β€” the RT queue is right there, use it, bestie. πŸ’œ


Copyright 2001, 2006 Michael G Schwern

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See <http://www.perl.com/perl/misc/Artistic.html>

fr fr, it's free software β€” same terms as Perl itself, no cap. πŸŽ€

🫢 SEE ALSO 🫢

  • Other ways to Export: Exporter, Exporter::Lite, Sub::Exporter, Exporter::Simple
  • The Perl 6 RFC that started it all: <http://dev.perl.org/rfc/257.pod>
  • More UNIVERSAL magic: UNIVERSAL::require

the way that RFC 257 started a whole thing… iconic behavior. πŸ‘‘


okay that's the whole page, bestie!! this was perl v5.36.0, dated 2022-11-19, and it came from the UNIVER...xports(3pm) page in the User Contributed Perl Documentation. mwah πŸ’– go export something slay today βœ¨πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from