New upstream snapshot.
Debian Janitor
1 year, 3 months ago
21 | 21 | Version 1, February 1989 |
22 | 22 | |
23 | 23 | Copyright (C) 1989 Free Software Foundation, Inc. |
24 | 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA | |
24 | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
25 | 25 | |
26 | 26 | Everyone is permitted to copy and distribute verbatim copies |
27 | 27 | of this license document, but changing it is not allowed. |
291 | 291 | |
292 | 292 | - "Package" refers to the collection of files distributed by the Copyright |
293 | 293 | Holder, and derivatives of that collection of files created through |
294 | textual modification. | |
294 | textual modification. | |
295 | 295 | - "Standard Version" refers to such a Package if it has not been modified, |
296 | 296 | or has been modified in accordance with the wishes of the Copyright |
297 | Holder. | |
297 | Holder. | |
298 | 298 | - "Copyright Holder" is whoever is named in the copyright or copyrights for |
299 | the package. | |
299 | the package. | |
300 | 300 | - "You" is you, if you're thinking about copying or distributing this Package. |
301 | 301 | - "Reasonable copying fee" is whatever you can justify on the basis of media |
302 | 302 | cost, duplication charges, time of people involved, and so on. (You will |
303 | 303 | not be required to justify it to the Copyright Holder, but only to the |
304 | computing community at large as a market that must bear the fee.) | |
304 | computing community at large as a market that must bear the fee.) | |
305 | 305 | - "Freely Available" means that no fee is charged for the item itself, though |
306 | 306 | there may be fees involved in handling the item. It also means that |
307 | 307 | recipients of the item may redistribute it under the same conditions they |
308 | received it. | |
308 | received it. | |
309 | 309 | |
310 | 310 | 1. You may make and give away verbatim copies of the source form of the |
311 | 311 | Standard Version of this Package without restriction, provided that you |
372 | 372 | |
373 | 373 | 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
374 | 374 | WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
375 | MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
375 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
376 | 376 | |
377 | 377 | The End |
378 | 378 |
0 | # This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.029. | |
0 | 1 | LICENSE |
1 | 2 | MANIFEST |
2 | 3 | META.json |
5 | 6 | README |
6 | 7 | dist.ini |
7 | 8 | lib/namespace/sweep.pm |
9 | t/except.t | |
8 | 10 | t/ns_a_also.t |
9 | 11 | t/ns_a_basic.t |
10 | 12 | t/ns_a_cleanee.t |
3 | 3 | "Mike Friedman <friedo@friedo.com>" |
4 | 4 | ], |
5 | 5 | "dynamic_config" : 0, |
6 | "generated_by" : "Dist::Zilla version 4.300026, CPAN::Meta::Converter version 2.120921", | |
6 | "generated_by" : "Dist::Zilla version 6.029, CPAN::Meta::Converter version 2.150010", | |
7 | 7 | "license" : [ |
8 | 8 | "perl_5" |
9 | 9 | ], |
10 | 10 | "meta-spec" : { |
11 | 11 | "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", |
12 | "version" : "2" | |
12 | "version" : 2 | |
13 | 13 | }, |
14 | 14 | "name" : "namespace-sweep", |
15 | 15 | "prereqs" : { |
16 | 16 | "configure" : { |
17 | 17 | "requires" : { |
18 | "ExtUtils::MakeMaker" : "6.30" | |
18 | "ExtUtils::MakeMaker" : "0" | |
19 | } | |
20 | }, | |
21 | "develop" : { | |
22 | "requires" : { | |
23 | "Test::More" : "0" | |
19 | 24 | } |
20 | 25 | }, |
21 | 26 | "runtime" : { |
22 | 27 | "requires" : { |
23 | 28 | "B::Hooks::EndOfScope" : "0.09", |
24 | 29 | "Carp" : "0", |
25 | "Data::Dumper" : "0", | |
26 | 30 | "List::Util" : "0", |
27 | 31 | "Package::Stash" : "0.33", |
28 | 32 | "Scalar::Util" : "0", |
40 | 44 | } |
41 | 45 | }, |
42 | 46 | "release_status" : "stable", |
43 | "resources" : { | |
44 | "repository" : { | |
45 | "type" : "git", | |
46 | "url" : "git://github.com/friedo/perl-namespace-sweep.git", | |
47 | "web" : "http://github.com/friedo/perl-namespace-sweep" | |
48 | } | |
49 | }, | |
50 | "version" : "0.006" | |
47 | "version" : "0.006", | |
48 | "x_generated_by_perl" : "v5.36.0", | |
49 | "x_serialization_backend" : "Cpanel::JSON::XS version 4.32", | |
50 | "x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later" | |
51 | 51 | } |
52 | 52 |
2 | 2 | author: |
3 | 3 | - 'Mike Friedman <friedo@friedo.com>' |
4 | 4 | build_requires: |
5 | Sub::Name: 0 | |
6 | Test::More: 0 | |
7 | overload: 0 | |
5 | Sub::Name: '0' | |
6 | Test::More: '0' | |
7 | overload: '0' | |
8 | 8 | configure_requires: |
9 | ExtUtils::MakeMaker: 6.30 | |
9 | ExtUtils::MakeMaker: '0' | |
10 | 10 | dynamic_config: 0 |
11 | generated_by: 'Dist::Zilla version 4.300026, CPAN::Meta::Converter version 2.120921' | |
11 | generated_by: 'Dist::Zilla version 6.029, CPAN::Meta::Converter version 2.150010' | |
12 | 12 | license: perl |
13 | 13 | meta-spec: |
14 | 14 | url: http://module-build.sourceforge.net/META-spec-v1.4.html |
15 | version: 1.4 | |
15 | version: '1.4' | |
16 | 16 | name: namespace-sweep |
17 | 17 | requires: |
18 | B::Hooks::EndOfScope: 0.09 | |
19 | Carp: 0 | |
20 | Data::Dumper: 0 | |
21 | List::Util: 0 | |
22 | Package::Stash: 0.33 | |
23 | Scalar::Util: 0 | |
24 | Sub::Identify: 0.04 | |
25 | strict: 0 | |
26 | warnings: 0 | |
27 | resources: | |
28 | repository: git://github.com/friedo/perl-namespace-sweep.git | |
29 | version: 0.006 | |
18 | B::Hooks::EndOfScope: '0.09' | |
19 | Carp: '0' | |
20 | List::Util: '0' | |
21 | Package::Stash: '0.33' | |
22 | Scalar::Util: '0' | |
23 | Sub::Identify: '0.04' | |
24 | strict: '0' | |
25 | warnings: '0' | |
26 | version: '0.006' | |
27 | x_generated_by_perl: v5.36.0 | |
28 | x_serialization_backend: 'YAML::Tiny version 1.73' | |
29 | x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later' |
0 | ||
0 | # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.029. | |
1 | 1 | use strict; |
2 | 2 | use warnings; |
3 | 3 | |
4 | 4 | |
5 | 5 | |
6 | use ExtUtils::MakeMaker 6.30; | |
7 | ||
8 | ||
6 | use ExtUtils::MakeMaker; | |
9 | 7 | |
10 | 8 | my %WriteMakefileArgs = ( |
11 | 9 | "ABSTRACT" => "Sweep up imported subs in your classes", |
12 | 10 | "AUTHOR" => "Mike Friedman <friedo\@friedo.com>", |
13 | "BUILD_REQUIRES" => { | |
14 | "Sub::Name" => 0, | |
15 | "Test::More" => 0, | |
16 | "overload" => 0 | |
17 | }, | |
18 | 11 | "CONFIGURE_REQUIRES" => { |
19 | "ExtUtils::MakeMaker" => "6.30" | |
12 | "ExtUtils::MakeMaker" => 0 | |
20 | 13 | }, |
21 | 14 | "DISTNAME" => "namespace-sweep", |
22 | "EXE_FILES" => [], | |
23 | 15 | "LICENSE" => "perl", |
24 | 16 | "NAME" => "namespace::sweep", |
25 | 17 | "PREREQ_PM" => { |
26 | 18 | "B::Hooks::EndOfScope" => "0.09", |
27 | 19 | "Carp" => 0, |
28 | "Data::Dumper" => 0, | |
29 | 20 | "List::Util" => 0, |
30 | 21 | "Package::Stash" => "0.33", |
31 | 22 | "Scalar::Util" => 0, |
32 | 23 | "Sub::Identify" => "0.04", |
33 | 24 | "strict" => 0, |
34 | 25 | "warnings" => 0 |
26 | }, | |
27 | "TEST_REQUIRES" => { | |
28 | "Sub::Name" => 0, | |
29 | "Test::More" => 0, | |
30 | "overload" => 0 | |
35 | 31 | }, |
36 | 32 | "VERSION" => "0.006", |
37 | 33 | "test" => { |
40 | 36 | ); |
41 | 37 | |
42 | 38 | |
43 | unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { | |
44 | my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; | |
45 | my $pp = $WriteMakefileArgs{PREREQ_PM}; | |
46 | for my $mod ( keys %$br ) { | |
47 | if ( exists $pp->{$mod} ) { | |
48 | $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; | |
49 | } | |
50 | else { | |
51 | $pp->{$mod} = $br->{$mod}; | |
52 | } | |
53 | } | |
39 | my %FallbackPrereqs = ( | |
40 | "B::Hooks::EndOfScope" => "0.09", | |
41 | "Carp" => 0, | |
42 | "List::Util" => 0, | |
43 | "Package::Stash" => "0.33", | |
44 | "Scalar::Util" => 0, | |
45 | "Sub::Identify" => "0.04", | |
46 | "Sub::Name" => 0, | |
47 | "Test::More" => 0, | |
48 | "overload" => 0, | |
49 | "strict" => 0, | |
50 | "warnings" => 0 | |
51 | ); | |
52 | ||
53 | ||
54 | unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { | |
55 | delete $WriteMakefileArgs{TEST_REQUIRES}; | |
56 | delete $WriteMakefileArgs{BUILD_REQUIRES}; | |
57 | $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; | |
54 | 58 | } |
55 | 59 | |
56 | 60 | delete $WriteMakefileArgs{CONFIGURE_REQUIRES} |
57 | 61 | unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; |
58 | 62 | |
59 | 63 | WriteMakefile(%WriteMakefileArgs); |
60 | ||
61 | ||
62 |
0 | ||
1 | ||
2 | 0 | This archive contains the distribution namespace-sweep, |
3 | 1 | version 0.006: |
4 | 2 | |
10 | 8 | the same terms as the Perl 5 programming language system itself. |
11 | 9 | |
12 | 10 | |
11 | This README file was generated by Dist::Zilla::Plugin::Readme v6.029. |
0 | libnamespace-sweep-perl (0.006+git20150107.1.db90b18-1) UNRELEASED; urgency=low | |
1 | ||
2 | * New upstream snapshot. | |
3 | ||
4 | -- Debian Janitor <janitor@jelmer.uk> Thu, 19 Jan 2023 03:10:36 -0000 | |
5 | ||
0 | 6 | libnamespace-sweep-perl (0.006-3) unstable; urgency=medium |
1 | 7 | |
2 | 8 | [ Salvatore Bonaccorso ] |
10 | 10 | skip = Moo |
11 | 11 | skip = Mouse |
12 | 12 | skip = Moose |
13 | skip = Moo::Role | |
13 | 14 | [TestRelease] |
14 | 15 | [ConfirmRelease] |
15 | 16 | [PkgVersion] |
0 | 0 | package namespace::sweep; |
1 | { | |
2 | $namespace::sweep::VERSION = '0.006'; | |
3 | } | |
4 | ||
1 | $namespace::sweep::VERSION = '0.006'; | |
5 | 2 | # ABSTRACT: Sweep up imported subs in your classes |
6 | 3 | |
7 | 4 | use strict; |
10 | 7 | use Scalar::Util 'blessed', 'reftype'; |
11 | 8 | use List::Util 'first'; |
12 | 9 | use Carp 'croak'; |
13 | use Data::Dumper; | |
14 | 10 | |
15 | 11 | use Sub::Identify 0.04 'get_code_info'; |
16 | 12 | use B::Hooks::EndOfScope 0.09 'on_scope_end'; |
22 | 18 | my ( $class, %args ) = @_; |
23 | 19 | |
24 | 20 | my $cleanee = exists $args{-cleanee} ? $args{-cleanee} : scalar caller; |
25 | my @alsos; | |
26 | ||
27 | if ( exists $args{-also} ) { | |
28 | if ( ref $args{-also} && ( reftype $args{-also} eq reftype [ ] ) ) { | |
29 | @alsos = @{ $args{-also} }; | |
30 | } else { | |
31 | @alsos = ( $args{-also} ); | |
21 | my %run_test = ( | |
22 | -also => sub { +return }, | |
23 | -except => sub { +return }, | |
24 | ); | |
25 | ||
26 | foreach my $t (keys %run_test) | |
27 | { | |
28 | next unless exists $args{$t}; | |
29 | ||
30 | unless ( ref $args{$t} and reftype($args{$t}) eq reftype([]) ) | |
31 | { | |
32 | $args{$t} = [ $args{$t} ]; | |
32 | 33 | } |
34 | ||
35 | my @tests; | |
36 | foreach my $arg (@{ $args{$t} }) { | |
37 | my $test = !$arg ? sub { 0 } | |
38 | : !ref( $arg ) ? sub { $_[0] eq $arg } | |
39 | : reftype $arg eq reftype sub { } ? sub { local $_ = $_[0]; $arg->() } | |
40 | : reftype $arg eq reftype qr// ? sub { $_[0] =~ $arg } | |
41 | : croak sprintf q{Don't know what to do with [%s] for %s}, $arg, $t; | |
42 | ||
43 | push @tests, $test; | |
44 | } | |
45 | ||
46 | $run_test{$t} = sub { | |
47 | return 1 if first { $_->( $_[0] ) } @tests; | |
48 | return; | |
49 | }; | |
33 | 50 | } |
34 | ||
35 | my @also_tests; | |
36 | foreach my $also( @alsos ) { | |
37 | my $test = !$also ? sub { 0 } | |
38 | : !ref( $also ) ? sub { $_[0] eq $also } | |
39 | : reftype $also eq reftype sub { } ? sub { local $_ = $_[0]; $also->() } | |
40 | : reftype $also eq reftype qr// ? sub { $_[0] =~ $also } | |
41 | : croak sprintf q{Don't know what to do with [%s] for -also}, $also; | |
42 | ||
43 | push @also_tests, $test; | |
44 | } | |
45 | ||
46 | my $run_test = sub { | |
47 | return 1 if first { $_->( $_[0] ) } @also_tests; | |
48 | return; | |
49 | }; | |
50 | 51 | |
51 | 52 | on_scope_end { |
52 | 53 | no strict 'refs'; |
81 | 82 | } |
82 | 83 | |
83 | 84 | foreach my $sym( keys %{ $st } ) { |
84 | $sweep->( $sym ) and next if $run_test->( $sym ); | |
85 | next if $run_test{-except}->( $sym ); | |
86 | $sweep->( $sym ) and next if $run_test{-also}->( $sym ); | |
85 | 87 | |
86 | 88 | next unless exists &{ $st . $sym }; |
87 | 89 | next if $keep{$sym}; |
102 | 104 | |
103 | 105 | =pod |
104 | 106 | |
107 | =encoding utf-8 | |
108 | ||
105 | 109 | =head1 NAME |
106 | 110 | |
107 | 111 | namespace::sweep - Sweep up imported subs in your classes |
112 | 116 | |
113 | 117 | =head1 SYNOPSIS |
114 | 118 | |
115 | package Foo; | |
116 | ||
117 | use namespace::sweep; | |
118 | use Some::Module qw(some_function); | |
119 | ||
120 | sub my_method { | |
121 | my $foo = some_function(); | |
122 | ... | |
123 | } | |
124 | ||
125 | package main; | |
126 | ||
127 | Foo->my_method; # ok | |
128 | Foo->some_function; # ERROR! | |
119 | package Foo; | |
120 | ||
121 | use namespace::sweep; | |
122 | use Some::Module qw(some_function); | |
123 | ||
124 | sub my_method { | |
125 | my $foo = some_function(); | |
126 | ... | |
127 | } | |
128 | ||
129 | package main; | |
130 | ||
131 | Foo->my_method; # ok | |
132 | Foo->some_function; # ERROR! | |
129 | 133 | |
130 | 134 | =head1 DESCRIPTION |
131 | 135 | |
136 | 140 | code inside your module will still be able to use the imported functions without any |
137 | 141 | problems. |
138 | 142 | |
139 | =encoding utf-8 | |
140 | ||
141 | 143 | =head1 ARGUMENTS |
142 | 144 | |
143 | 145 | The following arguments may be passed on the C<use> line: |
149 | 151 | If you want to clean a different class than the one importing this pragma, you can |
150 | 152 | specify it with this flag. Otherwise, the importing class is assumed. |
151 | 153 | |
152 | package Foo; | |
153 | use namespace::sweep -cleanee => 'Bar' # sweep up Bar.pm | |
154 | package Foo; | |
155 | use namespace::sweep -cleanee => 'Bar' # sweep up Bar.pm | |
154 | 156 | |
155 | 157 | =item -also |
156 | 158 | |
158 | 160 | normally be caught. (For example, private helper subs in your module's class that |
159 | 161 | should not be called as methods.) |
160 | 162 | |
161 | package Foo; | |
162 | use namespace::sweep -also => '_helper'; # sweep up single sub | |
163 | use namespace::sweep -also => [qw/foo bar baz/]; # list of subs | |
164 | use namespace::sweep -also => qr/^secret_/; # subs matching regex | |
163 | package Foo; | |
164 | use namespace::sweep -also => '_helper'; # sweep single sub | |
165 | use namespace::sweep -also => [qw/foo bar baz/]; # list of subs | |
166 | use namespace::sweep -also => qr/^secret_/; # matching regex | |
165 | 167 | |
166 | 168 | You can also specify a subroutine reference which will receive the symbol name as |
167 | 169 | C<$_>. If the sub returns true, the symbol will be swept. |
168 | 170 | |
169 | # sweep up those rude four-letter subs | |
170 | use namespace::sweep -also => sub { return 1 if length $_ == 4 } | |
171 | # sweep up those rude four-letter subs | |
172 | use namespace::sweep -also => sub { return 1 if length $_ == 4 } | |
171 | 173 | |
172 | 174 | You can also combine these methods into an array reference: |
173 | 175 | |
174 | use namespace::sweep -also => [ 'string', sub { 1 if /$pat/ and $_ !~ /$other/ }, qr/^foo_.+/ ]; | |
176 | use namespace::sweep -also => [ | |
177 | 'string', | |
178 | sub { 1 if /$pat/ and $_ !~ /$other/ }, | |
179 | qr/^foo_.+/, | |
180 | ]; | |
181 | ||
182 | =item -except | |
183 | ||
184 | This lets you specify subroutines which should be kept despite eveything else. | |
185 | For example, if you use L<Exporter> or L<Sub::Exporter>, you probably want to | |
186 | keep the C<import> method installed into your package: | |
187 | ||
188 | package Foo; | |
189 | use Exporter 'import'; | |
190 | use namespace::sweep -except => 'import'; | |
191 | ||
192 | If using sub attributes, then you may need to keep certain special subs: | |
193 | ||
194 | use namespace::sweep -except => qr{^(FETCH|MODIFY)_\w+_ATTRIBUTES$}; | |
195 | ||
196 | When a sub matches both C<< -also >> and C<< -except >>, then C<< -except >> "wins". | |
175 | 197 | |
176 | 198 | =back |
177 | 199 |
0 | use Test::More tests => 4; | |
1 | ||
2 | BEGIN { | |
3 | package Local::Clean; | |
4 | use Scalar::Util qw( blessed reftype ); | |
5 | use namespace::sweep; | |
6 | }; | |
7 | ||
8 | BEGIN { | |
9 | package Local::Dirty; | |
10 | use Scalar::Util qw( blessed reftype ); | |
11 | use namespace::sweep -except => 'blessed'; | |
12 | }; | |
13 | ||
14 | BEGIN { | |
15 | package Local::Filthy; | |
16 | use Scalar::Util qw( blessed reftype ); | |
17 | use namespace::sweep -except => [ qr{e} ]; | |
18 | }; | |
19 | ||
20 | BEGIN { | |
21 | package Local::Conflicting; | |
22 | sub foo { 1 }; | |
23 | use namespace::sweep -also => 'foo', -except => 'foo'; | |
24 | }; | |
25 | ||
26 | ok( | |
27 | !Local::Clean->can('blessed') && !Local::Clean->can('reftype'), | |
28 | 'default' | |
29 | ); | |
30 | ||
31 | ok( | |
32 | Local::Dirty->can('blessed') && !Local::Dirty->can('reftype'), | |
33 | '-except "subname"' | |
34 | ); | |
35 | ||
36 | ok( | |
37 | Local::Filthy->can('blessed') && Local::Filthy->can('reftype'), | |
38 | '-except qr{regex}' | |
39 | ); | |
40 | ||
41 | ok( | |
42 | Local::Conflicting->can('foo'), | |
43 | '-except beats -also' | |
44 | ); |
4 | 4 | or plan skip_all => 'This test requires Moo' |
5 | 5 | } |
6 | 6 | |
7 | { | |
7 | BEGIN { | |
8 | package Local::Noisy; | |
9 | use Moo::Role; | |
10 | requires 'noise'; | |
11 | sub loud_noise { uc(shift->noise) }; | |
12 | }; | |
13 | ||
14 | BEGIN { | |
8 | 15 | package Local::Cow; |
9 | 16 | use Moo; |
10 | 17 | use namespace::sweep; |
11 | } | |
18 | sub noise { 'moo' }; | |
19 | with qw( Local::Noisy ); | |
20 | }; | |
21 | ||
22 | ok not $INC{'Moose.pm'}; | |
12 | 23 | |
13 | 24 | can_ok 'Local::Cow' => qw( new ); |
14 | ok not $INC{'Moose.pm'}; | |
25 | can_ok 'Local::Cow' => qw( noise ); | |
26 | can_ok 'Local::Cow' => qw( loud_noise ); | |
27 | ||
28 | is( | |
29 | 'Local::Cow'->new->loud_noise, | |
30 | 'MOO', | |
31 | ); | |
32 | ||
15 | 33 | done_testing; |