SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Symony2 A Next Generation PHP Framework
Symony2 A Next Generation PHP FrameworkSymony2 A Next Generation PHP Framework
Symony2 A Next Generation PHP FrameworkRyan Weaver
 
High Performance Solution for PHP7
High Performance Solution for PHP7High Performance Solution for PHP7
High Performance Solution for PHP7Xinchen Hui
 
A brief to PHP 7.3
A brief to PHP 7.3A brief to PHP 7.3
A brief to PHP 7.3Xinchen Hui
 
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 radioCristopher Ewing
 
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 2016Clark Everetts
 
PHP7.1 New Features & Performance
PHP7.1 New Features & PerformancePHP7.1 New Features & Performance
PHP7.1 New Features & PerformanceXinchen Hui
 
Laravel Webcon 2015
Laravel Webcon 2015Laravel Webcon 2015
Laravel Webcon 2015Tim Bracken
 
Advanced Reflection in Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in PharoMarcus Denker
 
Creating Perl modules with Dist::Zilla
Creating Perl modules with Dist::ZillaCreating Perl modules with Dist::Zilla
Creating Perl modules with Dist::ZillaMark Gardner
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and DjangoMichael Pirnat
 
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 201244CON
 
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 youRyan Weaver
 
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)Ryan Weaver
 
Functional programming principles and Java 8
Functional programming principles and Java 8Functional programming principles and Java 8
Functional programming principles and Java 8Dragos Balan
 
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 timeAndreas Jung
 
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 ProgrammersDiego Freniche Brito
 
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 DenkerPharo
 

Tendances (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
 

En vedette

Getting started with Pod::Weaver
Getting started with Pod::WeaverGetting started with Pod::Weaver
Getting started with Pod::WeaverJoshua Keroes
 
Hank Torbert Avondale Ventures
Hank Torbert Avondale VenturesHank Torbert Avondale Ventures
Hank Torbert Avondale Ventureshanktorbert
 
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 Questhubneilbowers
 
Dist::Zilla - A very brief introduction
Dist::Zilla - A very brief introductionDist::Zilla - A very brief introduction
Dist::Zilla - A very brief introductionDean Hamstead
 

En vedette (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
 

Similaire à Perl 5 Exporter Modules Explained

Introduction to c first week slides
Introduction to c first week slidesIntroduction to c first week slides
Introduction to c first week slidesluqman bawany
 
Writing Better Haskell
Writing Better HaskellWriting Better Haskell
Writing Better Haskellnkpart
 
Packaging perl (LPW2010)
Packaging perl (LPW2010)Packaging perl (LPW2010)
Packaging perl (LPW2010)p3castro
 
Lotuscript for large systems
Lotuscript for large systemsLotuscript for large systems
Lotuscript for large systemsBill 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.pdfMichpice
 
Treasure Data Summer Internship 2016
Treasure Data Summer Internship 2016Treasure Data Summer Internship 2016
Treasure Data Summer Internship 2016Yuta Iwama
 
これからの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 typesSukhpreetSingh519414
 
Java developer trainee implementation and import
Java developer trainee implementation and importJava developer trainee implementation and import
Java developer trainee implementation and importiamluqman0403
 
Ansible module development 101
Ansible module development 101Ansible module development 101
Ansible module development 101yfauser
 
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.pptxnyomans1
 
Q-SPractical_introduction_to_Python.pptx
Q-SPractical_introduction_to_Python.pptxQ-SPractical_introduction_to_Python.pptx
Q-SPractical_introduction_to_Python.pptxJeromeTacata3
 
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.1Andrei KUCHARAVY
 
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 Dutyreedmaniac
 

Similaire à Perl 5 Exporter Modules Explained (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
 

Dernier

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
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 CCTVshikhaohhpro
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
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 Modelsaagamshah0812
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 

Dernier (20)

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
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
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
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
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 

Perl 5 Exporter Modules Explained

  • 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