On 3 July 2015 at 19:18, ayush kabra <ayush.kab...@gmail.com> wrote: > I want to make customized module on perl but i don't know how to make it. i > have checked on google but it's little bit confusing. i am not able to > understand what is the meaning of EXPORTER_OK ,IMPORT and there is lot of > thinh which i am not able to understand. Can you please send me some > examples of cusotmized module and explain it's functionality. what is the > work of @ISA, and @INA path?.
If you look in the manual for `perldoc -f use`, you'll see that "use" is a shorthand implies that a function called "import" will get called if such a one exists. Exporter.pm ( perldoc Exporter ) is a module that provides a stock version of this function, with some standard customizable settings: @EXPORT_OK is a "global" package variable with no /inherent/ meaning. However, if you're calling the "import" function provided by Exporter, that function will poke around in your package, and look for that variable, and use that variable to decide which functions to export. The question is, how does your package get this magic by exporter? Where How does Expoter.pm's import get called? That's where @ISA comes in, but doesn't have to. @ISA is a special variable used by Perl to dictate the inheritance of perl packages. So: package Foo; sub foo { print "This is Foo::foo" } package Bar; sub bar { print "This if Bar::bar" } package Quux; @ISA = ('Foo'); sub quux { print "This is Quux::quux"; } Here, Quux ->quux # prints Bar->bar # prints Foo->foo # prints Bar->foo # does not work, there's no 'foo' Quux->foo # DOES work, because finding no 'foo' in Quux, it looks up @ISA and finds 'foo' in Foo and calls that instead. So: Putting it all together: package Example; require Exporter; our @ISA = ('Exporter'); our @EXPORT_OK = ("example_sub"); sub example_sub { print "hello" }; In some script: package myscript; use Example ('example_sub'); example_sub(); How this flows: use Example ('example_sub'); -> triggers at BEGIN phase # Example.pm is required # Example->import() is checked for # Example->import is found in Exporter.pm by looking up @ISA # Exporter::import('Example', 'example_sub' ) gets called # Exporter finds @Example::EXPORT_OK # Exporter sees 'example_sub' in @EXPORT_OK # Exporter sees you passed 'example_sub' to import # Exporter creates 'myscript::example_sub' as a reference to Example::example_sub # Exporter returns from import example_sub(); # Calls the imported Example::example_sub and prints "hello" This is all covered in much more depth in perldoc perlmod perldoc -f use perldoc Exporter -- Kent KENTNL - https://metacpan.org/author/KENTNL -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/