1# $Header: /home/fergal/my/cvs/Exporter-Easy/lib/Exporter/Easiest.pm,v 1.5 2003/02/13 13:09:15 fergal Exp $ 2# Be lean. 3use strict; 4no strict 'refs'; 5 6package Exporter::Easiest; 7 8require 5.006; 9 10require Exporter::Easy; 11 12sub import 13{ 14 my $pkg = shift; 15 16 my $callpkg = caller(0); 17 18 @_ = ($callpkg, parse_spec(@_)); 19 20 goto &Exporter::Easy::set_export_vars; 21} 22 23sub parse_spec 24{ 25 # maybe we were passed a string or an array of strings, allow both 26 27 my @spec = grep { /\S/ } map { split(/\s+/) } @_; 28 29 my %spec; 30 31 my $key = ""; 32 33 while (@spec) 34 { 35 my $new_key = shift @spec; 36 my $arrow = shift @spec; 37 $arrow = "" unless defined($arrow); 38 die "Expected '=>' not '$arrow' after $new_key" unless ($arrow eq '=>'); 39 40 if ($new_key =~ s/^://) 41 { 42 # if the new key starts with a : then it and the following list are 43 # pushed onto the TAGS entry 44 45 push(@{$spec{TAGS}}, $new_key, suck_list(\@spec)); 46 } 47 else 48 { 49 $key = $new_key; 50 51 # VARS and ISA should aren't necessarily a list 52 53 if( 54 ($key =~ /^(VARS|ISA)$/ and $spec[0] =~ /^\d+$/) or 55 ($key eq 'ALL') 56 ) 57 { 58 $spec{$key} = shift @spec; 59 } 60 else 61 { 62 $spec{$key} = suck_list(\@spec); 63 } 64 } 65 } 66 67 return %spec; 68} 69 70sub suck_list 71{ 72 # takes a ref to a list and removes elements from the front of the list 73 # until the list is empty or it's 2 shift away from removing a => 74 75 # returns a ref to a list of the removed list elements 76 77 my $list = shift; 78 79 my @sucked; 80 81 while (@$list) 82 { 83 if ($#$list and ($list->[1] eq '=>')) 84 { 85 last; 86 } 87 else 88 { 89 push(@sucked, shift(@$list)); 90 } 91 } 92 93 return \@sucked; 94} 95 96=head1 NAME 97 98Exporter::Easiest - Takes even more drudgery out of Exporting symbols 99 100=head1 SYNOPSIS 101 102In module YourModule.pm: 103 104 package YourModule; 105 use Exporter::Easiest q( 106 EXPORT => :tag1 107 OK => munge frobnicate 108 :tag1 => a b c 109 :tag2 => :tag1 d e f 110 FAIL => f g h 111 ); 112 113In other files which wish to use YourModule: 114 115 use ModuleName qw(frobnicate); # import listed symbols 116 frobnicate ($left, $right) # calls YourModule::frobnicate 117 118=head1 DESCRIPTION 119 120The Exporter::Easiest module is a wrapper around Exporter::Easy. It allows 121you to pass the arguments into Exporter::Easy without all those tiresome []s 122and qw()s. You pass arguments in as a string or an array of strings. You no 123longer need to bracket lists or take references. If want, you can also leave 124out the TAGS key and just put tag definitions along with the other keys. 125 126The important thing to remember is that tags should be preceded by ':' 127everywhere, including to the left of the '=>', otherwise it'll get confused. 128And don't worry I haven't done something horribly pythonesque, whitespace is 129not significant, all the parsing logic revolves around the use of ':'s and 130'=>'s 131 132=head1 SEE ALSO 133 134For the real details on exporting symbols see Exporter and Exporter::Easy 135 136=head1 AUTHOR 137 138Written by Fergal Daly <fergal@esatclear.ie>. 139 140=head1 LICENSE 141 142Under the same license as Perl itself 143 144=cut 145