File Coverage

blib/lib/Sub/StrictDecl.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Sub::StrictDecl - detect undeclared subroutines in compilation
4              
5             =head1 SYNOPSIS
6              
7             use Sub::StrictDecl;
8              
9             no Sub::StrictDecl;
10              
11             =head1 DESCRIPTION
12              
13             This module provides optional checking of subroutine existence at
14             compile time. This checking detects mistyped subroutine names and
15             subroutines that the programmer forgot to import. Traditionally Perl
16             does not detect these errors until runtime, so it is easy for errors to
17             lurk in rarely-executed or untested code.
18              
19             Specifically, where checking is enabled, any reference to a specific
20             (compile-time-constant) package-based subroutine name is examined. If the
21             named subroutine has never been declared then an error is signalled
22             at compile time. This does not require that the subroutine be fully
23             defined: a forward declaration such as "C" suffices to suppress
24             the error. Imported subroutines qualify as declared. References that
25             are checked include not only subroutine calls but also pure referencing
26             such as "C<\&foo>".
27              
28             This checking is controlled by a lexically-scoped pragma. It is
29             therefore applied only to code that explicitly wants the checking, and
30             it is possible to locally disable checking if necessary. Checking might
31             need to be turned off for code that makes special arrangements to put
32             a subroutine in place at runtime, for example.
33              
34             =cut
35              
36             package Sub::StrictDecl;
37              
38 2     2   24135 { use 5.006; }
  2         9  
  2         89  
39 2     2   3739 use Lexical::SealRequireHints 0.006;
  2         1706  
  2         12  
40 2     2   64 use warnings;
  2         6  
  2         59  
41 2     2   10 use strict;
  2         5  
  2         162  
42              
43             our $VERSION = "0.003";
44              
45             require XSLoader;
46             XSLoader::load(__PACKAGE__, $VERSION);
47              
48             =head1 PACKAGE METHODS
49              
50             =over
51              
52             =item Sub::StrictDecl->import
53              
54             Turns on subroutine declaration checking in the lexical environment that
55             is currently compiling.
56              
57             =item Sub::StrictDecl->unimport
58              
59             Turns off subroutine declaration checking in the lexical environment
60             that is currently compiling.
61              
62             =back
63              
64             =head1 SEE ALSO
65              
66             L,
67             L
68              
69             =head1 AUTHOR
70              
71             Andrew Main (Zefram)
72              
73             =head1 COPYRIGHT
74              
75             Copyright (C) 2011 PhotoBox Ltd
76              
77             Copyright (C) 2011 Andrew Main (Zefram)
78              
79             =head1 LICENSE
80              
81             This module is free software; you can redistribute it and/or modify it
82             under the same terms as Perl itself.
83              
84             =cut
85              
86             1;