SlideShare a Scribd company logo
1 of 54
More than you ever wanted to know about Perl 5's 
Exporter modules 
Neil Bowers 
NEILB 
neil@bowers.com
44+ modules 
on CPAN!
Function library modules 
use Maths qw/ min /; 
$min = min(@values); 
package Maths; 
use parent 'Exporter'; 
sub min { ... } 
package Exporter; 
... 
sub import {...} 
You're writing 
one of these
Exporter.pm 
package Maths; 
use parent 'Exporter'; 
our @EXPORT = qw/ min max average /; 
our @EXPORT_OK = qw/ sin cos tan /; 
our %EXPORT_TAGS = ( 
list => [qw/ min max average /], 
trig => [qw/ sin cos tan /], 
); 
use Maths qw/ :list /; 
$minimum = min(@numbers);
My model for function libraries 
• Only functions exported 
• Don't export variables 
• No functions exported by default 
• You have to ask for ask for everything you want 
• No (unexpected) namespace pollution 
• Documents where functions in your code come from (but: tags)
Function::Exporter
What else might you want? 
• Default exports 
• Exporting variables 
• Different (better?) notation for specifying what and how to export 
• Tags 
• Constants (creating module which define & export them) 
• Import control 
• Anonymous subs (on import & export) 
• Generators (aka currying) 
• Combined class & function module 
• Create a mashup module (exporting things from other modules)
Default exports 
Specifying what users of your module get when they 
don't explicitly list anything for import
Exporter::Auto 
• All public functions in module exported by default 
• Doesn't export functions that start with an underscore 
• Namespace pollution
Simpler than Exporter.pm 
When you want more than a completely minimal 
exporter, but not as much as Exporter
Exporter::Lite 
• A lightweight subset of the classic Exporter functionality 
• Adds the import() function into your namespace 
• No support for tags, or other features beyond the above
Exporter::Easy 
• Basic usage is clean and simple 
• Has nice way to build up tags ...
Exporter::Shiny 
• Simple interface for optional exports: 
• Exporter::Shiny is syntactic sugar around Exporter::Tiny
Tags 
Defining named groups of the symbols available for 
import
Exporter::Easy 
• Good if you've got a lot of functions / groups 
• That's a lot of punctuation though ...
Exporter::Easiest
Exporting variables
Don't export variables! 
• http://c2.com/cgi/wiki?GlobalVariablesAreBad 
• http://programmers.stackexchange.com/questions/14810 
8/why-is-global-state-so-evil 
• and 
• and 
• and
Constants 
Making it easy to create modules that define and export 
constants, for example ones that are system-wide
Exporter + constant
Panda::Export 
• Function::Exporter + constants, in XS
Constant::Exporter 
• See also 
also supports 
defining of tags 
• Const::Exporter – exports immutable variables too (deps++) 
• Exporter::Constants – support module for Exporter.pm
Constant::Export::Lazy 
• Where the value of a constant might take a long time to 
compute, look up in a database, etc
Import control 
More flexible ways for your module's users to specify 
which symbols to import, and as what
Exporter 
• The import list is basically a query, read left to right 
• You can use a regexp to match what to import 
• And prefix with ! to negate a clause
Exporter::Tiny
Anonymous functions 
Exporting from, and import to, function references
Exporter::AutoClean 
• Export anonymous subs 
• People can import, but not dip into your namespace
Exporter::Tiny 
• Import into a scalar reference 
• Doesn't pollute your namespace 
• For example, if you're making all your public functions exportable
Alternate notations 
Other ways to specify what bits of your module to export
Attribute::Exporter 
• Attributes used to annotate each function with export 
rules 
• Good: export status obvious when you look at each function 
• Bad: verbose / noisy 
• See also: Exporter::Simple, Perl6::Export::Attrs
Exporter::NoWork
Export::Above 
• Export config spread through file, but not next to each func
Exporter::Declare 
• Declarative syntax, Moose stylee
Exporter::Declare 
• Or you can put the export status by each sub: 
• Or you can export an anonymous sub:
Exporter::Declare - tags 
• You can define tags up front: 
• Or specify the tagging with each sub:
Exporter::Declare 
• You can rename things when you import them: 
• And a bunch more features. Too many perhaps? 
• Like Moose/Moo, potential for a lightweight subset?
Exporter::Declare::Magic 
• Syntactic sugar for Exporter::Declare 
• But: depends on 18 CPAN distributions
Hybrid modules 
Creating modules that can be used either as a class, or 
as a function library
Class::Exporter
Making mashup modules 
Create a module that exports things from multiple other 
modules
Exporter::Cluster 
• Create module which export things from other modules
Import::Base
Generators, or currying 
Fixing arguments to functions at import time
Sub::Exporter 
• Basic usage – give list of subs for optional export 
• Defines a :all/-all tag 
• You can rename on import 
• The real power is in export generators though...
Sub::Exporter
Using a Sub::Exporter module 
• When importing, you can configure what sub you want 
• Adds an overhead to all sub calls 
• I've recently hit a case where this might be the right 
solution 
• How many users of the module are using generators...?
SEE ALSO 1/2 
• Badger::Exporter – Exporter + constants + hooks ++ 
• Sub::Exporter::Progressive – same interface as 
Sub::Exporter, which is only loaded if advanced features 
are used, otherwise uses Exporter 
• Exporter::LexicalVars – create a module that exports 
lexical variables (!) 
• Exporter::Proxy – like my Function::Exporter, but exports 
the whole typeglob and adds exports() for reflection
SEE ALSO 2/2 
• Exporter::Renaming – monkey-patches Exporter to 
provide a renaming capability 
• Export::Lexical, Exporter::Lexical – subs imported into 
lexical scope 
• Sub::Exporter::Simple – syntactic sugar for basic 
exporting with Sub::Exporter (just use Exporter[::Tiny]) 
• Sub::Import – Sub::Exporter-like semantics, importing 
from any module
Dependencies: the good
Dependencies: the bad & the ugly
Reverse dependencies
Observations 
• Documentation of exporter modules is often sub-optimal 
• Particularly for people writing their first exporting module 
• Very few modules make use of advanced features 
• Very few modules document their import features 
• If your module provides advanced import features, you need to let 
your users know 
• There's only one exporter module shipped with Perl 
• There are gaps above and below it
Conclusion 
• Exporter::Tiny is a good default for most users 
• Or Exporter if you don't want the non-core dependency 
• Exporter::Easy if you've got rich tag needs 
• Would be nice if Exporter::Tiny supported nested tags 
• Exporting constants? 
• Panda::Export for &CONSTANTS 
• Const::Fast + Exporter::Tiny for immutable variables 
• Misc others: 
• Import::Base for mashup modules 
• Sub::Exporter for generators 
• Export::AutoClean / Exporter::Tiny for namespace OCD types 
• Yoda says: 
• variables export you should not 
• OO or functions: pick one you should

More Related Content

What's hot

Frequently asked questions answered frequently - but now for the last time
Frequently asked questions answered frequently - but now for the last timeFrequently asked questions answered frequently - but now for the last time
Frequently asked questions answered frequently - but now for the last time
Andreas Jung
 

What's hot (20)

Symony2 A Next Generation PHP Framework
Symony2 A Next Generation PHP FrameworkSymony2 A Next Generation PHP Framework
Symony2 A Next Generation PHP Framework
 
High Performance Solution for PHP7
High Performance Solution for PHP7High Performance Solution for PHP7
High Performance Solution for PHP7
 
Variables in Pharo5
Variables in Pharo5Variables in Pharo5
Variables in Pharo5
 
A brief to PHP 7.3
A brief to PHP 7.3A brief to PHP 7.3
A brief to PHP 7.3
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
Ancient To Modern: Upgrading nearly a decade of Plone in public radio
Ancient To Modern: Upgrading nearly a decade of Plone in public radioAncient To Modern: Upgrading nearly a decade of Plone in public radio
Ancient To Modern: Upgrading nearly a decade of Plone in public radio
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016
 
PHP7.1 New Features & Performance
PHP7.1 New Features & PerformancePHP7.1 New Features & Performance
PHP7.1 New Features & Performance
 
Laravel Webcon 2015
Laravel Webcon 2015Laravel Webcon 2015
Laravel Webcon 2015
 
Advanced Reflection in Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in Pharo
 
Creating Perl modules with Dist::Zilla
Creating Perl modules with Dist::ZillaCreating Perl modules with Dist::Zilla
Creating Perl modules with Dist::Zilla
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 
Burp Plugin Development for Java n00bs - 44CON 2012
Burp Plugin Development for Java n00bs - 44CON 2012Burp Plugin Development for Java n00bs - 44CON 2012
Burp Plugin Development for Java n00bs - 44CON 2012
 
Dependency Injection: Make your enemies fear you
Dependency Injection: Make your enemies fear youDependency Injection: Make your enemies fear you
Dependency Injection: Make your enemies fear you
 
Being Dangerous with Twig (Symfony Live Paris)
Being Dangerous with Twig (Symfony Live Paris)Being Dangerous with Twig (Symfony Live Paris)
Being Dangerous with Twig (Symfony Live Paris)
 
Functional programming principles and Java 8
Functional programming principles and Java 8Functional programming principles and Java 8
Functional programming principles and Java 8
 
Frequently asked questions answered frequently - but now for the last time
Frequently asked questions answered frequently - but now for the last timeFrequently asked questions answered frequently - but now for the last time
Frequently asked questions answered frequently - but now for the last time
 
Get to Know AtoM's Codebase
Get to Know AtoM's CodebaseGet to Know AtoM's Codebase
Get to Know AtoM's Codebase
 
Functional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented ProgrammersFunctional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented Programmers
 
PharoDAYS 2015: Pharo Status - by Markus Denker
PharoDAYS 2015: Pharo Status - by Markus DenkerPharoDAYS 2015: Pharo Status - by Markus Denker
PharoDAYS 2015: Pharo Status - by Markus Denker
 

Viewers also liked (7)

Getting started with Pod::Weaver
Getting started with Pod::WeaverGetting started with Pod::Weaver
Getting started with Pod::Weaver
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Hank Torbert Avondale Ventures
Hank Torbert Avondale VenturesHank Torbert Avondale Ventures
Hank Torbert Avondale Ventures
 
Have more fun with Perl via Questhub
Have more fun with Perl via QuesthubHave more fun with Perl via Questhub
Have more fun with Perl via Questhub
 
Dist::Zilla - A very brief introduction
Dist::Zilla - A very brief introductionDist::Zilla - A very brief introduction
Dist::Zilla - A very brief introduction
 
Co-teaching can be wonderful !
Co-teaching can be wonderful !Co-teaching can be wonderful !
Co-teaching can be wonderful !
 
Hank torbert
Hank torbertHank torbert
Hank torbert
 

Similar to CPAN Exporter modules for Perl 5

Lotuscript for large systems
Lotuscript for large systemsLotuscript for large systems
Lotuscript for large systems
Bill Buchan
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdfQ-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Michpice
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
goccy
 
ppt notes for python language variable data types
ppt notes for python language variable data typesppt notes for python language variable data types
ppt notes for python language variable data types
SukhpreetSingh519414
 
Java developer trainee implementation and import
Java developer trainee implementation and importJava developer trainee implementation and import
Java developer trainee implementation and import
iamluqman0403
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx
Q-Step_WS_02102019_Practical_introduction_to_Python.pptxQ-Step_WS_02102019_Practical_introduction_to_Python.pptx
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx
nyomans1
 

Similar to CPAN Exporter modules for Perl 5 (20)

Introduction to c first week slides
Introduction to c first week slidesIntroduction to c first week slides
Introduction to c first week slides
 
Writing Better Haskell
Writing Better HaskellWriting Better Haskell
Writing Better Haskell
 
Packaging perl (LPW2010)
Packaging perl (LPW2010)Packaging perl (LPW2010)
Packaging perl (LPW2010)
 
Lotuscript for large systems
Lotuscript for large systemsLotuscript for large systems
Lotuscript for large systems
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdfQ-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
 
Treasure Data Summer Internship 2016
Treasure Data Summer Internship 2016Treasure Data Summer Internship 2016
Treasure Data Summer Internship 2016
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
 
Java applet
Java appletJava applet
Java applet
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
 
ppt notes for python language variable data types
ppt notes for python language variable data typesppt notes for python language variable data types
ppt notes for python language variable data types
 
Switching to Git
Switching to GitSwitching to Git
Switching to Git
 
Java developer trainee implementation and import
Java developer trainee implementation and importJava developer trainee implementation and import
Java developer trainee implementation and import
 
Ansible module development 101
Ansible module development 101Ansible module development 101
Ansible module development 101
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx
Q-Step_WS_02102019_Practical_introduction_to_Python.pptxQ-Step_WS_02102019_Practical_introduction_to_Python.pptx
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx
 
Q-SPractical_introduction_to_Python.pptx
Q-SPractical_introduction_to_Python.pptxQ-SPractical_introduction_to_Python.pptx
Q-SPractical_introduction_to_Python.pptx
 
C-Sharp 6.0 ver2
C-Sharp 6.0 ver2C-Sharp 6.0 ver2
C-Sharp 6.0 ver2
 
CPP06 - Functions
CPP06 - FunctionsCPP06 - Functions
CPP06 - Functions
 
Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1
 
Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Duty
 
presentation
presentationpresentation
presentation
 

Recently uploaded

Recently uploaded (20)

Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 

CPAN Exporter modules for Perl 5

  • 1. More than you ever wanted to know about Perl 5's Exporter modules Neil Bowers NEILB neil@bowers.com
  • 3. Function library modules use Maths qw/ min /; $min = min(@values); package Maths; use parent 'Exporter'; sub min { ... } package Exporter; ... sub import {...} You're writing one of these
  • 4. Exporter.pm package Maths; use parent 'Exporter'; our @EXPORT = qw/ min max average /; our @EXPORT_OK = qw/ sin cos tan /; our %EXPORT_TAGS = ( list => [qw/ min max average /], trig => [qw/ sin cos tan /], ); use Maths qw/ :list /; $minimum = min(@numbers);
  • 5. My model for function libraries • Only functions exported • Don't export variables • No functions exported by default • You have to ask for ask for everything you want • No (unexpected) namespace pollution • Documents where functions in your code come from (but: tags)
  • 7. What else might you want? • Default exports • Exporting variables • Different (better?) notation for specifying what and how to export • Tags • Constants (creating module which define & export them) • Import control • Anonymous subs (on import & export) • Generators (aka currying) • Combined class & function module • Create a mashup module (exporting things from other modules)
  • 8. Default exports Specifying what users of your module get when they don't explicitly list anything for import
  • 9. Exporter::Auto • All public functions in module exported by default • Doesn't export functions that start with an underscore • Namespace pollution
  • 10. Simpler than Exporter.pm When you want more than a completely minimal exporter, but not as much as Exporter
  • 11. Exporter::Lite • A lightweight subset of the classic Exporter functionality • Adds the import() function into your namespace • No support for tags, or other features beyond the above
  • 12. Exporter::Easy • Basic usage is clean and simple • Has nice way to build up tags ...
  • 13. Exporter::Shiny • Simple interface for optional exports: • Exporter::Shiny is syntactic sugar around Exporter::Tiny
  • 14. Tags Defining named groups of the symbols available for import
  • 15. Exporter::Easy • Good if you've got a lot of functions / groups • That's a lot of punctuation though ...
  • 18. Don't export variables! • http://c2.com/cgi/wiki?GlobalVariablesAreBad • http://programmers.stackexchange.com/questions/14810 8/why-is-global-state-so-evil • and • and • and
  • 19. Constants Making it easy to create modules that define and export constants, for example ones that are system-wide
  • 22. Constant::Exporter • See also also supports defining of tags • Const::Exporter – exports immutable variables too (deps++) • Exporter::Constants – support module for Exporter.pm
  • 23. Constant::Export::Lazy • Where the value of a constant might take a long time to compute, look up in a database, etc
  • 24. Import control More flexible ways for your module's users to specify which symbols to import, and as what
  • 25. Exporter • The import list is basically a query, read left to right • You can use a regexp to match what to import • And prefix with ! to negate a clause
  • 27. Anonymous functions Exporting from, and import to, function references
  • 28. Exporter::AutoClean • Export anonymous subs • People can import, but not dip into your namespace
  • 29. Exporter::Tiny • Import into a scalar reference • Doesn't pollute your namespace • For example, if you're making all your public functions exportable
  • 30. Alternate notations Other ways to specify what bits of your module to export
  • 31. Attribute::Exporter • Attributes used to annotate each function with export rules • Good: export status obvious when you look at each function • Bad: verbose / noisy • See also: Exporter::Simple, Perl6::Export::Attrs
  • 33. Export::Above • Export config spread through file, but not next to each func
  • 34. Exporter::Declare • Declarative syntax, Moose stylee
  • 35. Exporter::Declare • Or you can put the export status by each sub: • Or you can export an anonymous sub:
  • 36. Exporter::Declare - tags • You can define tags up front: • Or specify the tagging with each sub:
  • 37. Exporter::Declare • You can rename things when you import them: • And a bunch more features. Too many perhaps? • Like Moose/Moo, potential for a lightweight subset?
  • 38. Exporter::Declare::Magic • Syntactic sugar for Exporter::Declare • But: depends on 18 CPAN distributions
  • 39. Hybrid modules Creating modules that can be used either as a class, or as a function library
  • 41. Making mashup modules Create a module that exports things from multiple other modules
  • 42. Exporter::Cluster • Create module which export things from other modules
  • 44. Generators, or currying Fixing arguments to functions at import time
  • 45. Sub::Exporter • Basic usage – give list of subs for optional export • Defines a :all/-all tag • You can rename on import • The real power is in export generators though...
  • 47. Using a Sub::Exporter module • When importing, you can configure what sub you want • Adds an overhead to all sub calls • I've recently hit a case where this might be the right solution • How many users of the module are using generators...?
  • 48. SEE ALSO 1/2 • Badger::Exporter – Exporter + constants + hooks ++ • Sub::Exporter::Progressive – same interface as Sub::Exporter, which is only loaded if advanced features are used, otherwise uses Exporter • Exporter::LexicalVars – create a module that exports lexical variables (!) • Exporter::Proxy – like my Function::Exporter, but exports the whole typeglob and adds exports() for reflection
  • 49. SEE ALSO 2/2 • Exporter::Renaming – monkey-patches Exporter to provide a renaming capability • Export::Lexical, Exporter::Lexical – subs imported into lexical scope • Sub::Exporter::Simple – syntactic sugar for basic exporting with Sub::Exporter (just use Exporter[::Tiny]) • Sub::Import – Sub::Exporter-like semantics, importing from any module
  • 51. Dependencies: the bad & the ugly
  • 53. Observations • Documentation of exporter modules is often sub-optimal • Particularly for people writing their first exporting module • Very few modules make use of advanced features • Very few modules document their import features • If your module provides advanced import features, you need to let your users know • There's only one exporter module shipped with Perl • There are gaps above and below it
  • 54. Conclusion • Exporter::Tiny is a good default for most users • Or Exporter if you don't want the non-core dependency • Exporter::Easy if you've got rich tag needs • Would be nice if Exporter::Tiny supported nested tags • Exporting constants? • Panda::Export for &CONSTANTS • Const::Fast + Exporter::Tiny for immutable variables • Misc others: • Import::Base for mashup modules • Sub::Exporter for generators • Export::AutoClean / Exporter::Tiny for namespace OCD types • Yoda says: • variables export you should not • OO or functions: pick one you should