Main > Free Download Search >

Free packet tracer tutorial software for linux

packet tracer tutorial

Sponsored Links
Sponsored Links
Secleted [ 0 ] software to compare
Results 1 - 15 of about 829
Packet filtering setup script

Packet filtering setup script


Packet filtering setup script by Anthony C. Zboralski. more>>
Packet filtering setup script by Anthony C. Zboralski. Adapted by Didi Damian for iptables version 1.0.0

Sample:

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# Set up variables
EXT_IF="eth0"
INT_IF="eth1"
EXT_IP=24.x.x.x/32
INT_IP=192.168.0.1/32
EXT_NET=24.x.x.0/24
INT_NET=192.168.0.0/24
MASQ_NETS="192.168.0.0/24"
LOCAL_ADDRS="127.0.0.0/8 192.168.0.1/32 24.x.x.x/32"
MAIL_RELAY=24.x.x.x/32
SMB_ACCESS="192.168.0.2/32"
SMB_BCAST="192.168.0.255/32"

# Turn on IP forwarding
echo Turning on IP forwarding.
echo 1 > /proc/sys/net/ipv4/ip_forward

# Load the ip_tables module
echo Loading ip_tables module.
/sbin/modprobe ip_tables || exit 1
# I let the kernel dynamically load the other modules

echo Flush standard tables.
iptables --flush INPUT
iptables --flush OUTPUT
iptables --flush FORWARD
echo Deny everything until firewall setup is completed.
iptables --policy INPUT DROP
iptables --policy OUTPUT DROP
iptables --policy FORWARD DROP

CHAINS=`iptables -n -L |perl -n -e /Chains+(S+)/ && !($1 =~ /^(INPUT|FORWARD|OUTPUT)$/) && print "$1 "`
echo Remove remaining chains:
echo $CHAINS
for chain in $CHAINS; do
iptables --flush $chain
done
# 2nd step cause of dependencies
for chain in $CHAINS; do
iptables --delete-chain $chain
done

for net in $MASQ_NETS; do
# I delete all the rules so you can rerun the scripts without bloating
# your nat entries.
iptables -D POSTROUTING -t nat -s $MASQ_NETS -j MASQUERADE 2>/dev/null
iptables -A POSTROUTING -t nat -s $MASQ_NETS -j MASQUERADE || exit 1
done
iptables --policy FORWARD ACCEPT

# Create a target for logging and dropping packets
iptables --new LDROP 2>/dev/null
iptables -A LDROP --proto tcp -j LOG --log-level info
--log-prefix "TCP Drop "
iptables -A LDROP --proto udp -j LOG --log-level info
--log-prefix "UDP Drop "
iptables -A LDROP --proto icmp -j LOG --log-level info
--log-prefix "ICMP Drop "
iptables -A LDROP --proto gre -j LOG --log-level info
--log-prefix "GRE Drop "

iptables -A LDROP -f -j LOG --log-level emerg
--log-prefix "FRAG Drop "
iptables -A LDROP -j DROP

# Create a table for watching some accepting rules
iptables --new WATCH 2>/dev/null
iptables -A WATCH -m limit -j LOG --log-level warn --log-prefix "ACCEPT "
iptables -A WATCH -j ACCEPT


echo Special target for local addresses:
iptables --new LOCAL 2>/dev/null
echo $LOCAL_ADDRS
for ip in $LOCAL_ADDRS; do
iptables -A INPUT --dst $ip -j LOCAL
# iptables -A INPUT --src $ip -i ! lo -j LDROP # lame spoof protect
done
echo Authorize mail from mail relay.
iptables -A LOCAL --proto tcp --syn --src $MAIL_RELAY --dst $EXT_IP --dport 25 -j ACCEPT


echo Authorizing samba access to:
echo $SMB_ACCESS
iptables --new SMB 2>/dev/null
for ip in $SMB_ACCESS; do
iptables -A SMB -s $ip -j ACCEPT
done
iptables -A LOCAL --proto udp -i ! $EXT_IF --dport 135:139 -j SMB
iptables -A LOCAL --proto tcp -i ! $EXT_IF --dport 135:139 -j SMB
iptables -A LOCAL --proto tcp -i ! $EXT_IF --dport 445 -j SMB
iptables -A INPUT -i ! $EXT_IF --dst $SMB_BCAST -j ACCEPT #lame samba broadcast

echo Drop and log every other incoming tcp connection attempts.
iptables -A LOCAL -i ! lo --proto tcp --syn --j LDROP

echo Authorize dns access for local nets.
for net in $MASQ_NETS 127.0.0.0/8; do
iptables -A INPUT --proto udp --src $net --dport 53 -j ACCEPT
done


echo Enforcing up ICMP policies, use iptables -L ICMP to check.
# If you deny all ICMP messages you head for trouble since it would
# break lots of tcp/ip algorythm (acz)
iptables --new ICMP 2>/dev/null
iptables -A INPUT --proto icmp -j ICMP
iptables -A ICMP -p icmp --icmp-type echo-reply -j ACCEPT
iptables -A ICMP -p icmp --icmp-type destination-unreachable -j WATCH
iptables -A ICMP -p icmp --icmp-type network-unreachable -j WATCH
iptables -A ICMP -p icmp --icmp-type host-unreachable -j WATCH
iptables -A ICMP -p icmp --icmp-type protocol-unreachable -j WATCH
iptables -A ICMP -p icmp --icmp-type port-unreachable -j ACCEPT
iptables -A ICMP -p icmp --icmp-type fragmentation-needed -j LDROP
iptables -A ICMP -p icmp --icmp-type source-route-failed -j WATCH
iptables -A ICMP -p icmp --icmp-type network-unknown -j WATCH
iptables -A ICMP -p icmp --icmp-type host-unknown -j WATCH
iptables -A ICMP -p icmp --icmp-type network-prohibited -j WATCH
iptables -A ICMP -p icmp --icmp-type host-prohibited -j WATCH
iptables -A ICMP -p icmp --icmp-type TOS-network-unreachable -j WATCH
iptables -A ICMP -p icmp --icmp-type TOS-host-unreachable -j WATCH
iptables -A ICMP -p icmp --icmp-type communication-prohibited -j WATCH
iptables -A ICMP -p icmp --icmp-type host-precedence-violation -j LDROP
iptables -A ICMP -p icmp --icmp-type precedence-cutoff -j LDROP
iptables -A ICMP -p icmp --icmp-type source-quench -j LDROP
iptables -A ICMP -p icmp --icmp-type redirect -j LDROP
iptables -A ICMP -p icmp --icmp-type network-redirect -j LDROP
iptables -A ICMP -p icmp --icmp-type host-redirect -j LDROP
iptables -A ICMP -p icmp --icmp-type TOS-network-redirect -j LDROP
iptables -A ICMP -p icmp --icmp-type TOS-host-redirect -j LDROP
iptables -A ICMP -p icmp --icmp-type echo-request -j WATCH
iptables -A ICMP -p icmp --icmp-type router-advertisement -j LDROP
iptables -A ICMP -p icmp --icmp-type router-solicitation -j LDROP
iptables -A ICMP -p icmp --icmp-type time-exceeded -j WATCH
iptables -A ICMP -p icmp --icmp-type ttl-zero-during-transit -j WATCH
iptables -A ICMP -p icmp --icmp-type ttl-zero-during-reassembly -j WATCH
iptables -A ICMP -p icmp --icmp-type parameter-problem -j WATCH
iptables -A ICMP -p icmp --icmp-type ip-header-bad -j WATCH
iptables -A ICMP -p icmp --icmp-type required-option-missing -j WATCH
iptables -A ICMP -p icmp --icmp-type timestamp-request -j LDROP
iptables -A ICMP -p icmp --icmp-type timestamp-reply -j LDROP
iptables -A ICMP -p icmp --icmp-type address-mask-request -j LDROP
iptables -A ICMP -p icmp --icmp-type address-mask-reply -j LDROP
iptables -A ICMP -p icmp -j LDROP

echo Authorize tcp traffic.
iptables -A INPUT --proto tcp -j ACCEPT

echo Authorize packet output.
iptables --policy OUTPUT ACCEPT

#echo reject ident if you drop em you gotta wait for timeout
#iptables -I LOCAL --proto tcp --syn --dst $EXT_IP --dport 113 -j REJECT

echo Drop and log all udp below 1024.
iptables -A INPUT -i ! lo --proto udp --dport :1023 -j LDROP

echo Drop rpc dynamic udp port:
RPC_UDP=`rpcinfo -p localhost|perl -n -e /.*udps+(d+)s+/ && print $1,"n"|sort -u`
echo $RPC_UDP
for port in $RPC_UDP; do
iptables -A LOCAL -i ! lo --proto udp --dport $port -j LDROP
done

echo Authorize udp above 1024.
iptables -A INPUT --proto udp --dport 1024: -j ACCEPT
<<less
Download (MB)
Added: 2007-02-14 License: GPL (GNU General Public License) Price:
984 downloads
Apache::PAR::tutorial 0.30

Apache::PAR::tutorial 0.30


Apache::PAR::tutorial is a Perl module with information on getting Apache::PAR up and running. more>>
Apache::PAR::tutorial is a Perl module with information on getting Apache::PAR up and running.

Apache::PAR is a framework for including Perl ARchive files in a mod_perl (1.x or 2.x) environment. It allows an author to package up a web application, including configuration, static files, Perl modules, and Registry and PerlRun scripts to include in a single file. This archive can then be moved to other locations on the same system or distributed and loaded with a single set of configuration options in the Apache configuration.

These modules are based on PAR.pm by Autrijus Tang and Archive::Zip by Ned Konz as well as the mod_perl modules. They extend the concept of PAR files to mod_perl, similar to how WAR archives work for Java. An archive (which is really a zip file), contains one or more elements which can be served to clients making requests to an Apache web server. Scripts, modules, and static content should then be able to be served from within the .par archive without modifications.

For the package developer

For the package developer, Apache::PAR allows for easy package management, which frees the author from the task of creating a full Perl package. Apache::PAR allows the package developer to set the required Apache configuration directly in a package which greatly simplifies the install process for the end user and gives the the developer the ability to assign URLs which remain the same on all systems that the package is installed on. It is possible to decompress the contents of the PAR file during startup, which allows the use of code which relies on outside content (templating systems, etc)

For the package user

Once Apache::PAR is installed, it can be configured in an Apache configuration file with as little as two lines. Once setup, to add a new .par package to the system a user only has to place the package in the directory specified in the Apache configuration and restart Apache. All other configuration needs are provided by the module itself.

<<less
Download (0.025MB)
Added: 2006-10-12 License: Perl Artistic License Price:
1107 downloads
PAR::Tutorial 0.941

PAR::Tutorial 0.941


PAR::Tutorial is a cross-platform Packaging and Deployment with PAR. more>>
PAR::Tutorial is a cross-platform Packaging and Deployment with PAR.

SYNOPSIS

This is a tutorial on PAR, first appeared at the 7th Perl Conference. The HTML version of this tutorial is available online as http://aut.dyndns.org/par-tutorial/.

On Deploying Perl Applications

% sshnuke.pl 10.2.2.2 -rootpw="Z1ON0101"
Perl v5.6.1 required--this is only v5.6.0, stopped at sshnuke.pl line 1.
BEGIN failed--compilation aborted at sshnuke.pl line 1.

Q: "Help! I cant run your program!"
A1: Install Perl & perl -MCPAN -einstall(...)
How do we know which modules are needed?
New versions of CPAN modules may break sshnuke.pl
A2: Install Perl & tar zxf my_perllib.tgz
Possibly overwriting existing modules; not cross-platform at all
A3: Use the executable generated by perlcc sshnuke.pl
Impossible to debug; perlcc usually does not work anyway

<<less
Download (0.19MB)
Added: 2006-07-20 License: Perl Artistic License Price:
1194 downloads
IPTables-tutorial 1.2.2

IPTables-tutorial 1.2.2


IPTables-tutorials aim is to explain iptables in a complete and simple way. more>>
IPTables-tutorials aim is to explain iptables in a complete and simple way. The iptables-tutorial is currently rather stable, and contains information on all the currently available matches and targets (in kernel), as well as a couple of complete example scripts and explanations. It contains a complete section on iptables syntax, as well as other interesting commands such as iptables-save and iptables-restore.

The tutorial has recently been under heavy scrutiny and updating, as can be seen in this, the latest version of the tutorial. It is now also available in bookform from Lulu.com. If you feel like contributing or donating to the author of this tutorial, please do buy the book! Thank you!

If you need help, you are better off by asking the netfilter mailing list which you can reach at netfilter at lists.netfilter.org. For more information on this, visit the netfilter mailinglist page. You may also contact the linuxsecurity mailing list at security-discuss AT linuxsecurity dotcom. Both are fairly large, and should be able to help you much much better than I can.

<<less
Download (9.0MB)
Added: 2006-11-22 License: (FDL) GNU Free Documentation License Price:
669 downloads
Prima::tutorial 1.20

Prima::tutorial 1.20


Prima::tutorial is an introductory tutorial. more>>
Prima::tutorial is an introductory tutorial.

Programming graphic interfaces is often considered somewhat boring, and not without a cause. It is a small pride in knowing that your buttons and scrollbars work exactly as millions of others buttons and scrollbars do, so whichever GUI toolkit is chosen, it is usually regarded as a tool of small importance, and the less obtrusive, the better.

Given that, and trying to live up to the famous Perl making easy things easy and hard things possible mantra, this manual page is an introductory tutorial meant to show how to write easy things easy. The hard things are explained in the other Prima manual pages ( see Prima ).

<<less
Download (1.4MB)
Added: 2006-08-24 License: Perl Artistic License Price:
1162 downloads
Packet Debugger 0.1 Beta

Packet Debugger 0.1 Beta


Packet Debugger presents a debugger-like UI for pcap packet capture files. more>>
Packet Debugger presents a debugger-like UI for pcap packet capture files.

The Packet Debugger (pdb) allows users to work with packet streams as if they were working with a source code debugger.

Users can list, inspect, modify, and retransmit any packet from captured files, as well as work with live packet captures.

<<less
Download (0.15MB)
Added: 2007-01-20 License: BSD License Price:
1010 downloads
Packet Garden 1.0pre5

Packet Garden 1.0pre5


Packet Garden is a project that allows you to grow a world from network traffic. more>>
Packet Garden is a project that allows you to grow a world from network traffic.

Packet Garden captures information about how you use the internet and uses this stored information to grow a private world you can later explore.

To do this, Packet Garden takes note of all the servers you visit, their geographical location and the kinds of data you access.

Uploads make hills and downloads valleys, their location determined by numbers taken from internet address itself.

The size of each hill or valley is based on how much data is sent or received.

Plants are also grown for each protocol detected by the software; if you visit a website, an HTTP plant is grown. If you share some files via eMule, a Peer to Peer plant is grown, and so on.

<<less
Download (2.5MB)
Added: 2007-01-16 License: GPL (GNU General Public License) Price:
1015 downloads
Imager::Tutorial 0.54

Imager::Tutorial 0.54


Imager::Tutorial is an introduction to Imager. more>>
Imager::Tutorial is an introduction to Imager.

Before you start

If you have the necessary knowledge, install the image format libraries you want Imager image file support for, and Imager itself, otherwise arrange to have it done.
You will also want some sort of image viewer tool, whether an image editor like Photoshop or the GIMP, or a web browser.

Hello Boxes! - A Simple Start

As with any perl program its useful to start with a #! line, and to enable strict mode:

#!/usr/bin/perl -w
# you might to use warnings; instead of the -w above
use strict;

These lines will be omitted in further examples.

As with any module, you need to load it:

use Imager;

Now create a image to draw on:

my $image = Imager->new(xsize => 100, ysize => 100);

and draw a couple of filled rectangles on it:

$image->box(xmin => 0, ymin => 0, xmax => 99, ymax => 99,
filled => 1, color => blue);
$image->box(xmin => 20, ymin => 20, xmax => 79, ymax => 79,
filled => 1, color => green);

Since the first box fills the whole image, it can be simplified to:

$image->box(filled => 1, color => blue);

and save it to a file:

$image->write(file=>tutorial1.ppm)
or die Cannot save tutorial1.ppm: , $image->errstr;

So our completed program is:

use Imager;

my $image = Imager->new(xsize => 100, ysize => 100);

$image->box(filled => 1, color => blue);
$image->box(xmin => 20, ymin => 20, xmax => 79, ymax => 79,
filled => 1, color => green);

$image->write(file=>tutorial1.ppm)
or die Cannot save tutorial1.ppm: , $image->errstr;

<<less
Download (0.83MB)
Added: 2006-10-27 License: Perl Artistic License Price:
1094 downloads
Array::Each::Tutorial 0.02

Array::Each::Tutorial 0.02


Array::Each::Tutorial - POD giving various examples how to use Array::Each. more>>
Array::Each::Tutorial - POD giving various examples how to use Array::Each.

SYNOPSIS

man Array::Each
man Array::Each::Tutorial

or

perldoc Array::Each
perldoc Array::Each::Tutorial

Overview

This tutorial contains only POD, so dont do this:

use Array::Each::Tutorial; # dont do this

Rather, simply read the POD (as you are doing). But first, please read the docs for Array::Each, because the whole scoop is there.

This tutorial is intended to augment those docs with examples showing situations where you might want to use Array::Each instead of other techniques.

EXAMPLES

Parallel Arrays vs. Using a Hash

First of all, use a hash. Its almost always the best solution if you want to associate a "key" with a "value". And there are modules available that will let you do wonderful things with hashes, like keeping the keys sorted or keeping them in the order they were added.

So given a hash, you might at some point want to do this:

my %h = ( a=>1, b=>2, c=>3, d=>4, e=>5 );
while( my( $k, $v ) = each %h ) {
# ... do something with $k and $v ...
}

On the other hand, if parallel arrays better implement your algorithm, then you may find you want to do something like this:

my @k = qw( a b c d e );
my @v = qw( 1 2 3 4 5 );
for my $i ( 0 .. $#k ) {
my( $k, $v ) = ( $k[$i], $v[$i] );
# ... do something with $k and $v (and maybe $i) ...
}

Using Array::Each, you could do the same thing this way:

use Array::Each;
my @k = qw( a b c d e );
my @v = qw( 1 2 3 4 5 );
my $obj = Array::Each->new( @k, @v );
while( my( $k, $v, $i ) = $obj->each ) {
# ... do something with $k and $v (and maybe $i) ...
}

If you dont need $i at all, you can leave it out, e.g.,

while( my( $k, $v ) = $obj->each ) {
# ... do something with $k and $v ...
}

If you have more than two parallel arrays, include them all in the call to new() and add as many "capture" variables as you need, e.g.,

my @k = qw( a b c d e );
my @v = qw( 1 2 3 4 5 );
my @p = qw( - + ~ = : );
my $obj = Array::Each->new( @k, @v, @p );
while( my( $k, $v, $p, $i ) = $obj->each ) {
# ... do something with $k, $v, and $p (and maybe $i) ...
}

<<less
Download (0.020MB)
Added: 2007-07-14 License: Perl Artistic License Price:
832 downloads
KDE Simple Programming Tutorial 1.2

KDE Simple Programming Tutorial 1.2


KDE Simple Programming Tutorial is a tutorial for developing a KDE application. more>>
KDE Simple Programming Tutorial is a tutorial for developing a KDE application.

With the only requirement of a little C++ knowledge, and using the latest KDE snapshots, the reader will learn how to build his/her first KDE application from a simple "Hello world" button to a Web browser with a DCOP interface that communicates with a bookmark application running in a separate process.

Theres also a spanish and a romanian version of the documentation.
<<less
Download (MB)
Added: 2006-10-04 License: GPL (GNU General Public License) Price:
1121 downloads
Beesoft Tracer 0.04

Beesoft Tracer 0.04


Beesoft Tracer is a suite of tools for a remote debugging of running program. more>>
Beesoft Tracer project is a suite of tools for a remote debugging of running program. All elements are wrote in pure C++ with using STL library. The communication between elements is via sockets: so called unix domain socket and TCP/IP.

Elements of Beesoft Tracer system:

In whole process are used three applications.

1) the debugged program, which sends informations about own states to the server,
2) the trace server, named tracesrv, is a program collecting all information coming from the debugged program. The information can be send to one client program, if this is connected.
3) the trace client, receives information from the trace server, and displays them in text mode. GUI client is already in development and will be soon available.

Advantages of system:

- the debugged program is executed only a bit slower, almost goes normal and simultaneously sends all debugging information, which need a programmer for debugging. Information are sent to the server via unix domain socket.
- the client program, which displays received information, can be in other computer - in remote host (or at the same). Information are receiving via TCP/IP protocol.

How can you use it?

To debugging the remote program it is needed:

1) download source code of Beesoft Tracer to disk,
2) build a library libbstrace and the programs tracesrv and tracecli (use make ),
3) add a appropriate macros into the source code of the program which should be debugged (macros are defined in the header file Tracer.h) and in compile time link static library libbstrace.a.
After that you are ready for debugging!

To run the debugging enviroment:

1) start (followed programs must be run on the same machine):

a) first tracesrv
b) next debugged program ( for tests in packet is accesible program example),

2) on remote or on the same machine start client tracecli.

In the package file you can find the source code of the example program. There you can see the right using of necessary macros!

<<less
Download (0.044MB)
Added: 2007-07-29 License: GPL (GNU General Public License) Price:
817 downloads
Gantry::Docs::Tutorial 3.40

Gantry::Docs::Tutorial 3.40


Gantry::Docs::Tutorial is a Perl module for The Gantry Tutorial. more>>
Gantry::Docs::Tutorial is a Perl module for The Gantry Tutorial.

Gantry is a mature web framework, released in late 2005 onto an unsuspecting world. For more information on the framework, its features and history, see Gantry::Docs::About.
Here we will explore the basic workings of Gantry by constructing a very simple application. Dont let the simplicity of this example fool you -- this framework has extreme flexibility in delivering applications with web and scripted components. The example in this document is only to get you started.

This document begins by describing a simple one-table management application. It walks through the process of building the application. Then, it shows a tool -- called Bigtop -- which can be used to build the application from a relatively small configuration file. Finally, it shows how to add another table and regenerate the app via Bigtop.

<<less
Download (0.19MB)
Added: 2006-09-26 License: Perl Artistic License Price:
1123 downloads
Packet Construction Set 0.5 Beta

Packet Construction Set 0.5 Beta


Packet Construction Set is a set of Python modules and objects that make building network protocol code easier. more>>
Packet Construction Set is a set of Python modules and objects that make building network protocol code easier for the protocol developer.
The core of the system is the pcs module itself which provides the necessary functionality to create classes that implement packets.
Installation Instructions for Packet Construction Set (PCS)
PCS follows the normal Python conventions for building and installing and there is very little, if any, magic. To install the library and the associated packet classes into your system do:
> python setup.py install < return >
To test your installation do:
> cd tests/ < return >
> python *.py
Some tests fail if you do not have enough privileges to work with the Berkeley Packet Filter. If you wish to run those tests run them using sudo.
To build the documentation you will need pdflatex and a BSD version of make installed. Go into the docs directory and build the documentation:
> cd docs/ < return >
> bsdmake all
you will see PDF versions of the docs.
Enhancements:
- Move my version of Doug Songs Python pcap library into the package.
- Update the Makefile to make sure that we install correctly no matter what target is selected.
<<less
Download (0.36MB)
Added: 2007-03-22 License: BSD License Price:
947 downloads
MARC::Doc::Tutorial 2.00

MARC::Doc::Tutorial 2.00


MARC::Doc::Tutorial is a documentation-only module for new users of MARC::Record. more>>
MARC::Doc::Tutorial is a documentation-only module for new users of MARC::Record.

SYNOPSIS

perldoc MARC::Doc::Tutorial

What is MARC?

The MAchine Readable Cataloging format was designed by the Library of Congress in the late 1960s in order to allow libraries to convert their card catalogs into a digital format. The advantages of having computerized card catalogs were soon realized, and now MARC is being used by all sorts of libraries around the world to provide computerized access to their collections. MARC data in transmission format is optimized for processing by computers, so its not very readable for the normal human. For more about the MARC format, visit the Library of Congress at http://www.loc.gov/marc/

What is this Tutorial?

The document you are reading is a beginners guide to using Perl to processing MARC data, written in the cookbook style. Inside, you will find recipes on how to read, write, update and convert MARC data using the MARC::Record CPAN package. As with any cookbook, you should feel free to dip in at any section and use the recipe you find interesting.

If you are new to Perl, you may want to read from the beginning.
The document you are reading is distributed with the MARC::Record package, however in case you are reading it somewhere else, you can find the latest version at CPAN: http://www.cpan.org/modules/by-module/MARC/. Youll notice that some sections arent filled in yet, which is a result of this document being a work in progress. If you have ideas for new sections please make a suggestion to perl4lib: http://www.rice.edu/perl4lib/.

<<less
Download (0.77MB)
Added: 2007-07-10 License: GPL (GNU General Public License) Price:
836 downloads
Sub::Exporter::Tutorial 0.970

Sub::Exporter::Tutorial 0.970


Sub::Exporter::Tutorial is a friendly guide to exporting with Sub::Exporter. more>>
Sub::Exporter::Tutorial is a friendly guide to exporting with Sub::Exporter.

Whats an Exporter?

When you use a module, first it is required, then its import method is called. The Perl documentation tells us that the following two lines are equivalent:

use Module LIST;

BEGIN { require Module; Module->import(LIST); }

The import method is the modules exporter.

The Basics of Sub::Exporter

Sub::Exporter builds a custom exporter which can then be installed into your module. It builds this method based on configuration passed to its setup_exporter method.

A very basic use case might look like this:

package Addition;
use Sub::Exporter;
Sub::Exporter::setup_exporter({ exports => [ qw(plus) ]});

sub plus { my ($x, $y) = @_; return $x + $y; }

This would mean that when someone used your Addition module, they could have its plus routine imported into their package:

use Addition qw(plus);

my $z = plus(2, 2); # this works, because now plus is in the main package

That syntax to set up the exporter, above, is a little verbose, so for the simple case of just naming some exports, you can write this:

use Sub::Exporter -setup => { exports => [ qw(plus) ] };
...which is the same as the original example -- except that now the exporter is built and installed at compile time. Well, that and you typed less.

Using Export Groups

You can specify whole groups of things that should be exportable together. These are called groups. Exporter calls these tags. To specify groups, you just pass a groups key in your exporter configuration:

package Food;
use Sub::Exporter -setup => {
exports => [ qw(apple banana beef fluff lox rabbit) ],
groups => {
fauna => [ qw(beef lox rabbit) ],
flora => [ qw(apple banana) ],
}
};

Now, to import all that delicious foreign meat, your consumer needs only to write:

use Food qw(:fauna);
use Food qw(-fauna);

Either one of the above is acceptable. A colon is more traditional, but barewords with a leading colon cant be enquoted by a fat arrow. Well see why that matters later on.

Groups can contain other groups. If you include a group name (with the leading dash or colon) in a group definition, it will be expanded recursively when the exporter is called. The exporter will not recurse into the same group twice while expanding groups.

There are two special groups: all and default. The all group is defined by default, and contains all exportable subs. You can redefine it, if you want to export only a subset when all exports are requested. The default group is the set of routines to export when nothing specific is requested. By default, there is no default group.

<<less
Download (0.034MB)
Added: 2006-10-16 License: Perl Artistic License Price:
1104 downloads
Secleted [ 0 ] software to compare
  • Page: 1 of 5
  • 1
  • 2
  • 3
  • 4
  • 5