blib/lib/ExtUtils/FindFunctions.pm

filter: Statementstmt 66.6% 24 / 36 Branchbran 60.0% 6 / 10 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 70.9% 39 / 55 CC 11 SCAR 30.8
CC
11
Cov
67%
have_functions
29.4
BEGIN
1.0
BEGIN
1.0
CRAP 21.8
↑ Summary
1 package ExtUtils::FindFunctions;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use DynaLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 require Exporter;
6  
7 3 ▶{ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 $VERSION = '0.02';
9 3 @ISA = qw(Exporter);
10 3 @EXPORT = qw(&have_functions);
11 }
12  
13 =head1 NAME
14  
15 ExtUtils::FindFunctions - Find functions in external libraries
16  
17 =head1 VERSION
18  
19 Version 0.02
20  
21 =head1 SYNOPSIS
22  
23 use ExtUtils::FindFunctions;
24  
25 my @check = qw(pcap_findalldevs pcap_open_dead pcap_setnonblock pcap_lib_version);
26 my @funcs = have_functions(libs => '-lpcap', funcs => \@check, return_as => 'array');
27  
28 =head1 DESCRIPTION
29  
30 This module provides the C<have_functions()> function which can be used to
31 check if given functions are provided by an external library. Its aim is
32 to be used as an embedded library by F<Makefile.PL> which needs such
33 facilities. Use the B<install-extutils-findfunctions> command to embed it
34 in your distribution.
35  
36 =head1 EXPORT
37  
38 The module exports by default the C<have_functions()> function.
39  
40 =head1 FUNCTIONS
41  
42 =head2 have_functions()
43  
44 Load the specified libraries and search for the given functions names.
45 The results are returned as an array or as an hash depending on the
46 C<return_as> parameter.
47  
48 B<Parameters>
49  
50 =over
51  
52 =item *
53  
54 C<libs> - specify the libraries to load; this argument will be given
55 to C<DynaLoader::dl_findfile()>
56  
57 =item *
58  
59 C<funcs> - a reference to the list of functions to search
60  
61 =item *
62  
63 C<return_as> - specify the type of the result, either as an C<array>
64 or as a C<hash>. As an array, only the functions found in the libraries
65 are returned. As a hash, the keys are the function names and their value
66 indicates if the function is present or not.
67  
68 =back
69  
70 =cut
71  
72 5 ▶sub have_functions {
Subroutine have_functions: called CC=11 SCAR=33.8
Pod documented
73 5 my %args = @_;
74 5 my %funcs = ();
75  
76 # check params
77 5 ▶ defined $args{$_} or croak "error: Missing parameter '$_'.\n" for qw(libs funcs return_as);
Branch: 1 branch
BranchTrueFalseTotal
defined $args{$_} or croak("error: Missing parameter '${_}'.\n") 9 3 12
78  
79 2 ▶ $args{return_as} ||= 'array';
Condition100%2/2
$args{"return_as"} ||= "array"
l!l
11
MC/DC100%1/1
$args{"return_as"} ||= "array"
$args{"return_as"}
Truth table100%2/2
A
A= $args{"return_as"}
Aresult
11
00
80 2 ▶ $args{return_as} =~ /^(?:array|hash)$/
Branch: 1 branch
BranchTrueFalseTotal
$args{"return_as"} =~ /^(?:array|hash)$/ or croak("error: Incorrect value for parameter 'return_as'.\n") 1 1 2
81 or croak "error: Incorrect value for parameter 'return_as'.\n";
82  
83 my @libs = ref $args{libs} eq '' ? $args{libs}
84 0 ▶ : ref $args{libs} eq 'ARRAY' ? @{$args{libs}}
Branch: 2 branches
BranchTrueFalseTotal
ref $args{'libs'} eq '' ? : 0 1 1
ref $args{'libs'} eq 'ARRAY' ? : 0 1 1
85 : croak "error: Incorrect argument for parameter 'libs'.\n";
86  
87 # search for functions
88 0 for my $lib (@libs) {
89 0 my @paths = DynaLoader::dl_findfile($lib);
90  
91 0 for my $path (@paths) {
92 0 my $libref = DynaLoader::dl_load_file($path);
93  
94 0 for my $func (@{$args{funcs}}) {
95 0 my $symref = DynaLoader::dl_find_symbol($libref, $func);
96 0 $funcs{$func} = ! ! defined $symref;
97 }
98  
99 0 DynaLoader::dl_unload_file($libref);
100 }
101 }
102  
103 return $args{return_as} eq 'hash' ? %funcs
104 0 ▶ : grep { $funcs{$_} } sort keys %funcs;
Branch: 1 branch
BranchTrueFalseTotal
$args{'return_as'} eq 'hash' ? : 0 0 0
105 }
106  
107  
108 =head1 AUTHOR
109  
110 SE<eacute>bastien Aperghis-Tramoni, C<< <sebastien at aperghis.net> >>
111  
112  
113 =head1 BUGS
114  
115 Please report any bugs or feature requests to
116 C<bug-extutils-findfunctions at rt.cpan.org>, or through the web interface at
117 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ExtUtils-FindFunctions>.
118 I will be notified, and then you'll automatically be notified of progress on
119 your bug as I make changes.
120  
121  
122 =head1 SUPPORT
123  
124 You can find documentation for this module with the perldoc command.
125  
126 perldoc ExtUtils::FindFunctions
127  
128 You can also look for information at:
129  
130 =over
131  
132 =item * AnnoCPAN: Annotated CPAN documentation
133  
134 L<http://annocpan.org/dist/ExtUtils-FindFunctions>
135  
136 =item * CPAN Ratings
137  
138 L<http://cpanratings.perl.org/d/ExtUtils-FindFunctions>
139  
140 =item * RT: CPAN's request tracker
141  
142 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=ExtUtils-FindFunctions>
143  
144 =item * Search CPAN
145  
146 L<http://search.cpan.org/dist/ExtUtils-FindFunctions>
147  
148 =back
149  
150  
151 =head1 COPYRIGHT & LICENSE
152  
153 Copyright 2006 SE<eacute>bastien Aperghis-Tramoni, all rights reserved.
154  
155 This program is free software; you can redistribute it and/or modify it
156 under the same terms as Perl itself.
157  
158 =cut
159  
160 3 1; # End of ExtUtils::FindFunctions
↑ Summary