Currently I am creating a new module and I was wondering how can I apply my module to 2 things .
We often look like Usage
:
My: Use the module qw (something);
For example:
Use CGI :: Carp QW (Weightlibrobrobor);
So the first question is, how do I get it, I mean that the user has specified anything and what has he specified? The AP requested a simple module test code:
package mine :: module; # $ Id $ hard to use; Use carp; Sub new {my $ class = shift; My $ self = {}; $ Self- & gt; {ARG1} = Anf; $ Self- & gt; {ARG2} = Anf; $ Self- & gt; {ARG3} = Anf; $ Self- & gt; {ARG4} = Anf; Blessings ($ Self, $ Square); Return $ self; } Sub arg1 {my $ self = shift; If (@_) {$ self-> gt; {ARG1} = shift} $ self-> {ARG1}; } Sub arg2 {my $ self = shift; If (@_) {$ self-> gt; (ARG2} = shift} $ self-> {ARG2};} sub arg3 {my $ self = shift; if (@_) {$ self-> gt; {ARG3} = shift} $ self- & gt; {ARG3};} Sub arg4 {my $ self = shift} if {$ self-> gt; {ARG4} = shift} $ self-> {ARG4}}} sub dump {my $ self = Shift; Data is required: Dumper; My $ d = Data :: Dumper-> New ([$ self], [ref $ self]); $ D & gt; Deepcopy (1); Return $ d- & Gt; dump ();} 1; # then it is required or used
Import
subroutine gets passed in a usage
The following code samples can help you.
File: My / module PM
Package My :: Module; Use warnings; Strict use; Use data: Dumper ; Sub import {My ($ package, @args) = @_; Print dumper \ @args;} 1;
File: module.pl
#! / Usr / bin / env perl Use warnings; Strict use; Use my :: module qw (some);
If you are programming object-oriented modules, then you can try that you will save a lot of time.
Comments
Post a Comment