File Coverage

blib/lib/Exporter/Easiest.pm
Criterion Covered Total %
statement 40 40 100.0
branch 10 10 100.0
condition 9 9 100.0
subroutine 7 7 100.0
pod 0 2 0.0
total 66 68 97.0


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