Codebase list libnamespace-sweep-perl / fresh-snapshots/main
New upstream snapshot. Debian Janitor 1 year, 3 months ago
11 changed file(s) with 216 addition(s) and 122 deletion(s). Raw diff Collapse all Expand all
2121 Version 1, February 1989
2222
2323 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
2525
2626 Everyone is permitted to copy and distribute verbatim copies
2727 of this license document, but changing it is not allowed.
291291
292292 - "Package" refers to the collection of files distributed by the Copyright
293293 Holder, and derivatives of that collection of files created through
294 textual modification.
294 textual modification.
295295 - "Standard Version" refers to such a Package if it has not been modified,
296296 or has been modified in accordance with the wishes of the Copyright
297 Holder.
297 Holder.
298298 - "Copyright Holder" is whoever is named in the copyright or copyrights for
299 the package.
299 the package.
300300 - "You" is you, if you're thinking about copying or distributing this Package.
301301 - "Reasonable copying fee" is whatever you can justify on the basis of media
302302 cost, duplication charges, time of people involved, and so on. (You will
303303 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.)
305305 - "Freely Available" means that no fee is charged for the item itself, though
306306 there may be fees involved in handling the item. It also means that
307307 recipients of the item may redistribute it under the same conditions they
308 received it.
308 received it.
309309
310310 1. You may make and give away verbatim copies of the source form of the
311311 Standard Version of this Package without restriction, provided that you
372372
373373 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
374374 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
375 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
375 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
376376
377377 The End
378378
0 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.029.
01 LICENSE
12 MANIFEST
23 META.json
56 README
67 dist.ini
78 lib/namespace/sweep.pm
9 t/except.t
810 t/ns_a_also.t
911 t/ns_a_basic.t
1012 t/ns_a_cleanee.t
33 "Mike Friedman <friedo@friedo.com>"
44 ],
55 "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",
77 "license" : [
88 "perl_5"
99 ],
1010 "meta-spec" : {
1111 "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
12 "version" : "2"
12 "version" : 2
1313 },
1414 "name" : "namespace-sweep",
1515 "prereqs" : {
1616 "configure" : {
1717 "requires" : {
18 "ExtUtils::MakeMaker" : "6.30"
18 "ExtUtils::MakeMaker" : "0"
19 }
20 },
21 "develop" : {
22 "requires" : {
23 "Test::More" : "0"
1924 }
2025 },
2126 "runtime" : {
2227 "requires" : {
2328 "B::Hooks::EndOfScope" : "0.09",
2429 "Carp" : "0",
25 "Data::Dumper" : "0",
2630 "List::Util" : "0",
2731 "Package::Stash" : "0.33",
2832 "Scalar::Util" : "0",
4044 }
4145 },
4246 "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"
5151 }
5252
22 author:
33 - 'Mike Friedman <friedo@friedo.com>'
44 build_requires:
5 Sub::Name: 0
6 Test::More: 0
7 overload: 0
5 Sub::Name: '0'
6 Test::More: '0'
7 overload: '0'
88 configure_requires:
9 ExtUtils::MakeMaker: 6.30
9 ExtUtils::MakeMaker: '0'
1010 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'
1212 license: perl
1313 meta-spec:
1414 url: http://module-build.sourceforge.net/META-spec-v1.4.html
15 version: 1.4
15 version: '1.4'
1616 name: namespace-sweep
1717 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.
11 use strict;
22 use warnings;
33
44
55
6 use ExtUtils::MakeMaker 6.30;
7
8
6 use ExtUtils::MakeMaker;
97
108 my %WriteMakefileArgs = (
119 "ABSTRACT" => "Sweep up imported subs in your classes",
1210 "AUTHOR" => "Mike Friedman <friedo\@friedo.com>",
13 "BUILD_REQUIRES" => {
14 "Sub::Name" => 0,
15 "Test::More" => 0,
16 "overload" => 0
17 },
1811 "CONFIGURE_REQUIRES" => {
19 "ExtUtils::MakeMaker" => "6.30"
12 "ExtUtils::MakeMaker" => 0
2013 },
2114 "DISTNAME" => "namespace-sweep",
22 "EXE_FILES" => [],
2315 "LICENSE" => "perl",
2416 "NAME" => "namespace::sweep",
2517 "PREREQ_PM" => {
2618 "B::Hooks::EndOfScope" => "0.09",
2719 "Carp" => 0,
28 "Data::Dumper" => 0,
2920 "List::Util" => 0,
3021 "Package::Stash" => "0.33",
3122 "Scalar::Util" => 0,
3223 "Sub::Identify" => "0.04",
3324 "strict" => 0,
3425 "warnings" => 0
26 },
27 "TEST_REQUIRES" => {
28 "Sub::Name" => 0,
29 "Test::More" => 0,
30 "overload" => 0
3531 },
3632 "VERSION" => "0.006",
3733 "test" => {
4036 );
4137
4238
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;
5458 }
5559
5660 delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
5761 unless eval { ExtUtils::MakeMaker->VERSION(6.52) };
5862
5963 WriteMakefile(%WriteMakefileArgs);
60
61
62
0
1
20 This archive contains the distribution namespace-sweep,
31 version 0.006:
42
108 the same terms as the Perl 5 programming language system itself.
119
1210
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
06 libnamespace-sweep-perl (0.006-3) unstable; urgency=medium
17
28 [ Salvatore Bonaccorso ]
1010 skip = Moo
1111 skip = Mouse
1212 skip = Moose
13 skip = Moo::Role
1314 [TestRelease]
1415 [ConfirmRelease]
1516 [PkgVersion]
00 package namespace::sweep;
1 {
2 $namespace::sweep::VERSION = '0.006';
3 }
4
1 $namespace::sweep::VERSION = '0.006';
52 # ABSTRACT: Sweep up imported subs in your classes
63
74 use strict;
107 use Scalar::Util 'blessed', 'reftype';
118 use List::Util 'first';
129 use Carp 'croak';
13 use Data::Dumper;
1410
1511 use Sub::Identify 0.04 'get_code_info';
1612 use B::Hooks::EndOfScope 0.09 'on_scope_end';
2218 my ( $class, %args ) = @_;
2319
2420 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} ];
3233 }
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 };
3350 }
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 };
5051
5152 on_scope_end {
5253 no strict 'refs';
8182 }
8283
8384 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 );
8587
8688 next unless exists &{ $st . $sym };
8789 next if $keep{$sym};
102104
103105 =pod
104106
107 =encoding utf-8
108
105109 =head1 NAME
106110
107111 namespace::sweep - Sweep up imported subs in your classes
112116
113117 =head1 SYNOPSIS
114118
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!
129133
130134 =head1 DESCRIPTION
131135
136140 code inside your module will still be able to use the imported functions without any
137141 problems.
138142
139 =encoding utf-8
140
141143 =head1 ARGUMENTS
142144
143145 The following arguments may be passed on the C<use> line:
149151 If you want to clean a different class than the one importing this pragma, you can
150152 specify it with this flag. Otherwise, the importing class is assumed.
151153
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
154156
155157 =item -also
156158
158160 normally be caught. (For example, private helper subs in your module's class that
159161 should not be called as methods.)
160162
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
165167
166168 You can also specify a subroutine reference which will receive the symbol name as
167169 C<$_>. If the sub returns true, the symbol will be swept.
168170
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 }
171173
172174 You can also combine these methods into an array reference:
173175
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".
175197
176198 =back
177199
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 );
44 or plan skip_all => 'This test requires Moo'
55 }
66
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 {
815 package Local::Cow;
916 use Moo;
1017 use namespace::sweep;
11 }
18 sub noise { 'moo' };
19 with qw( Local::Noisy );
20 };
21
22 ok not $INC{'Moose.pm'};
1223
1324 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
1533 done_testing;