1 package Package::Constants;
4 use vars qw[$VERSION $DEBUG];
11 Package::Constants - List all constants declared in a package
15 use Package::Constants;
17 ### list the names of all constants in a given package;
18 @const = Package::Constants->list( __PACKAGE__ );
19 @const = Package::Constants->list( 'main' );
21 ### enable debugging output
22 $Package::Constants::DEBUG = 1;
26 C<Package::Constants> lists all the constants defined in a certain
27 package. This can be useful for, among others, setting up an
28 autogenerated C<@EXPORT/@EXPORT_OK> for a Constants.pm file.
32 =head2 @const = Package::Constants->list( PACKAGE_NAME );
34 Lists the names of all the constants defined in the provided package.
41 return unless defined $pkg; # some joker might use '0' as a pkg...
43 _debug("Inspecting package '$pkg'");
47 my $stash = $pkg . '::';
49 for my $name (sort keys %$stash ) {
51 _debug( " Checking stash entry '$name'" );
54 my $sub = $pkg->can( $name );
55 next unless defined $sub;
57 _debug( " '$name' is a coderef" );
59 next unless defined prototype($sub) and
60 not length prototype($sub);
62 _debug( " '$name' is a constant" );
70 =head1 GLOBAL VARIABLES
72 =head2 $Package::Constants::DEBUG
74 When set to true, prints out debug information to STDERR about the
75 package it is inspecting. Helps to identify issues when the results
76 are not as you expect.
82 sub _debug { warn "@_\n" if $DEBUG; }
88 Please report bugs or other issues to E<lt>bug-package-constants@rt.cpan.org<gt>.
92 This module by Jos Boumans E<lt>kane@cpan.orgE<gt>.
96 This library is free software; you may redistribute and/or modify it
97 under the same terms as Perl itself.
102 # c-indentation-style: bsd
104 # indent-tabs-mode: nil
106 # vim: expandtab shiftwidth=4: