| 1 | package Carp::Clan::Share; | ||
| 2 | |||
| 3 | 4 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 4 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | Carp::Clan::Share - Share your Carp::Clan settings with your whole Clan | ||
| 9 | |||
| 10 | =head1 VERSION | ||
| 11 | |||
| 12 | Version 0.013 | ||
| 13 | |||
| 14 | =cut | ||
| 15 | |||
| 16 | 4 | our $VERSION = '0.013'; | |
| 17 | |||
| 18 | 4 | require Carp::Clan; | |
| 19 | |||
| 20 | 4 | ▶ | sub import { |
|
Subroutine
import: called CC=1 SCAR=0.0
| |||
| 21 | 4 | my $caller = caller(0); | |
| 22 | 4 | my @arguments = @_; | |
| 23 | 4 | shift @arguments; # Get rid of the package name | |
| 24 | 4 | $caller =~ s/::Carp$//; # If the user already named it Carp, use the parent of that. | |
| 25 | 4 | unshift @arguments, "^${caller}::"; | |
| 26 | |||
| 27 | 4 | my $package = "${caller}::Carp"; | |
| 28 | 4 | my $pm = join("/", split m/::/, $package) . ".pm"; | |
| 29 | 4 | $INC{$pm} = 1; | |
| 30 | 4 | eval "package $package;"; | |
| 31 | |||
| 32 | 4 | my $exporter; | |
| 33 | { | ||
| 34 | 4 | ▶ | no strict 'refs'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 35 | 4 | ▶ | $exporter = *{"${package}::import"} = sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 36 | 14 | push @_, @arguments; | |
| 37 | 14 | goto &Carp::Clan::import; | |
| 38 | 4 | }; | |
| 39 | } | ||
| 40 | |||
| 41 | 4 | goto &$exporter; | |
| 42 | } | ||
| 43 | |||
| 44 | =head1 SYNOPSIS | ||
| 45 | |||
| 46 | package My::Namespace | ||
| 47 | |||
| 48 | use Carp::Clan::Share; # My::Namespace::Carp now exists | ||
| 49 | |||
| 50 | ... | ||
| 51 | |||
| 52 | package My::Namespace::Module | ||
| 53 | |||
| 54 | use My::Namespace::Carp; # Acts like "use Carp::Clan qw/^My::Namespace::/;" | ||
| 55 | |||
| 56 | ... | ||
| 57 | |||
| 58 | package My::Other::Namespace; | ||
| 59 | |||
| 60 | # You can also pass options through to Carp::Clan | ||
| 61 | use Carp::Clan::Share qw/verbose/; # My::Other::Namespace::Carp now exists | ||
| 62 | |||
| 63 | ... | ||
| 64 | |||
| 65 | package My::Other::Namespace::Module | ||
| 66 | |||
| 67 | use My::Other::Namespace::Carp; # Acts like "use Carp::Clan qw/^My::Other::Namespace:: verbose/;" | ||
| 68 | |||
| 69 | ... | ||
| 70 | |||
| 71 | =head1 DESCRIPTION | ||
| 72 | |||
| 73 | This is a very lightweight helper module (actually just an import method) that will automagically create | ||
| 74 | a __PACKAGE__::Carp module for you. | ||
| 75 | |||
| 76 | Any arguments passed to the import (e.g. via use) method are forwarded along to Carp::Clan. | ||
| 77 | |||
| 78 | NOTE: If you use this from a package ending with ::Carp, then it will use the parent of of that package | ||
| 79 | as the target namespace | ||
| 80 | |||
| 81 | package My::Namespace::Carp; | ||
| 82 | |||
| 83 | use Carp::Clan::Share; | ||
| 84 | |||
| 85 | package My::Namespace::Module | ||
| 86 | |||
| 87 | use My::Namespace::Carp; # Acts like "use Carp::Clan qw/^My::Namespace::/;" | ||
| 88 | |||
| 89 | =head1 SEE ALSO | ||
| 90 | |||
| 91 | L<Carp::Clan> | ||
| 92 | |||
| 93 | L<Carp> | ||
| 94 | |||
| 95 | =head1 AUTHOR | ||
| 96 | |||
| 97 | Robert Krimen, C<< <rkrimen at cpan.org> >> | ||
| 98 | |||
| 99 | =head1 BUGS | ||
| 100 | |||
| 101 | Please report any bugs or feature requests to C<bug-carp-clan-share at rt.cpan.org>, or through | ||
| 102 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Carp-Clan-Share>. I will be notified, and then you'll | ||
| 103 | automatically be notified of progress on your bug as I make changes. | ||
| 104 | |||
| 105 | |||
| 106 | |||
| 107 | |||
| 108 | =head1 SUPPORT | ||
| 109 | |||
| 110 | You can find documentation for this module with the perldoc command. | ||
| 111 | |||
| 112 | perldoc Carp::Clan::Share | ||
| 113 | |||
| 114 | |||
| 115 | You can also look for information at: | ||
| 116 | |||
| 117 | =over 4 | ||
| 118 | |||
| 119 | =item * RT: CPAN's request tracker | ||
| 120 | |||
| 121 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Carp-Clan-Share> | ||
| 122 | |||
| 123 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 124 | |||
| 125 | L<http://annocpan.org/dist/Carp-Clan-Share> | ||
| 126 | |||
| 127 | =item * CPAN Ratings | ||
| 128 | |||
| 129 | L<http://cpanratings.perl.org/d/Carp-Clan-Share> | ||
| 130 | |||
| 131 | =item * Search CPAN | ||
| 132 | |||
| 133 | L<http://search.cpan.org/dist/Carp-Clan-Share> | ||
| 134 | |||
| 135 | =back | ||
| 136 | |||
| 137 | |||
| 138 | =head1 ACKNOWLEDGEMENTS | ||
| 139 | |||
| 140 | |||
| 141 | =head1 COPYRIGHT & LICENSE | ||
| 142 | |||
| 143 | Copyright 2008 Robert Krimen | ||
| 144 | |||
| 145 | This program is free software; you can redistribute it and/or modify it | ||
| 146 | under the same terms as Perl itself. | ||
| 147 | |||
| 148 | |||
| 149 | =cut | ||
| 150 | |||
| 151 | 4 | 1; # End of Carp::Clan::Share | |