line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dist::Zilla::Plugin::PkgDist 6.030; |
2
|
|
|
|
|
|
|
# ABSTRACT: add a $DIST to your packages |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
2100
|
use Moose; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
27
|
|
5
|
|
|
|
|
|
|
with( |
6
|
|
|
|
|
|
|
'Dist::Zilla::Role::FileMunger', |
7
|
|
|
|
|
|
|
'Dist::Zilla::Role::FileFinderUser' => { |
8
|
|
|
|
|
|
|
default_finders => [ ':InstallModules', ':ExecFiles' ], |
9
|
|
|
|
|
|
|
}, |
10
|
|
|
|
|
|
|
'Dist::Zilla::Role::PPI', |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
13967
|
use Dist::Zilla::Pragmas; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
20
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
22
|
use namespace::autoclean; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
18
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
18
|
|
|
|
|
|
|
#pod |
19
|
|
|
|
|
|
|
#pod This plugin will add a line like the following to each package in each Perl |
20
|
|
|
|
|
|
|
#pod module or program (more or less) within the distribution: |
21
|
|
|
|
|
|
|
#pod |
22
|
|
|
|
|
|
|
#pod { our $DIST = 'My-CPAN-Dist'; } # where 'My-CPAN-Dist' is your dist name |
23
|
|
|
|
|
|
|
#pod |
24
|
|
|
|
|
|
|
#pod It will skip any package declaration that includes a newline between the |
25
|
|
|
|
|
|
|
#pod C<package> keyword and the package name, like: |
26
|
|
|
|
|
|
|
#pod |
27
|
|
|
|
|
|
|
#pod package |
28
|
|
|
|
|
|
|
#pod Foo::Bar; |
29
|
|
|
|
|
|
|
#pod |
30
|
|
|
|
|
|
|
#pod This sort of declaration is also ignored by the CPAN toolchain, and is |
31
|
|
|
|
|
|
|
#pod typically used when doing monkey patching or other tricky things. |
32
|
|
|
|
|
|
|
#pod |
33
|
|
|
|
|
|
|
#pod =cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub munge_files { |
36
|
1
|
|
|
1
|
0
|
4
|
my ($self) = @_; |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
3
|
$self->munge_file($_) for @{ $self->found_files }; |
|
1
|
|
|
|
|
6
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub munge_file { |
42
|
9
|
|
|
9
|
0
|
2749
|
my ($self, $file) = @_; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# XXX: for test purposes, for now! evil! -- rjbs, 2010-03-17 |
45
|
9
|
50
|
|
|
|
39
|
return if $file->name =~ /^corpus\//; |
46
|
|
|
|
|
|
|
|
47
|
9
|
50
|
|
|
|
29
|
return if $file->name =~ /\.t$/i; |
48
|
9
|
50
|
|
|
|
28
|
return $self->munge_perl($file) if $file->name =~ /\.(?:pm|pl)$/i; |
49
|
0
|
0
|
|
|
|
0
|
return $self->munge_perl($file) if $file->content =~ /^#!(?:.*)perl(?:$|\s)/; |
50
|
0
|
|
|
|
|
0
|
return; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub munge_perl { |
54
|
9
|
|
|
9
|
0
|
24
|
my ($self, $file) = @_; |
55
|
|
|
|
|
|
|
|
56
|
9
|
|
|
|
|
256
|
my $dist_name = $self->zilla->name; |
57
|
|
|
|
|
|
|
|
58
|
9
|
|
|
|
|
35
|
my $document = $self->ppi_document_for_file($file); |
59
|
|
|
|
|
|
|
|
60
|
9
|
100
|
|
|
|
2322
|
return unless my $package_stmts = $document->find('PPI::Statement::Package'); |
61
|
|
|
|
|
|
|
|
62
|
8
|
100
|
|
|
|
5962
|
if ($self->document_assigns_to_variable($document, '$DIST')) { |
63
|
3
|
|
|
|
|
14
|
$self->log([ 'skipping %s: assigns to $DIST', $file->name ]); |
64
|
3
|
|
|
|
|
1046
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
5
|
|
|
|
|
11
|
my %seen_pkg; |
68
|
|
|
|
|
|
|
|
69
|
5
|
|
|
|
|
14
|
for my $stmt (@$package_stmts) { |
70
|
9
|
|
|
|
|
1623
|
my $package = $stmt->namespace; |
71
|
|
|
|
|
|
|
|
72
|
9
|
100
|
|
|
|
259
|
if ($seen_pkg{ $package }++) { |
73
|
1
|
|
|
|
|
6
|
$self->log([ 'skipping package re-declaration for %s', $package ]); |
74
|
1
|
|
|
|
|
281
|
next; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
8
|
100
|
|
|
|
23
|
if ($stmt->content =~ /package\s*\n\s*\Q$package/) { |
78
|
1
|
|
|
|
|
67
|
$self->log([ 'skipping private package %s', $package ]); |
79
|
1
|
|
|
|
|
300
|
next; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# the \x20 hack is here so that when we scan *this* document we don't find |
83
|
|
|
|
|
|
|
# an assignment to version; it shouldn't be needed, but it's been annoying |
84
|
|
|
|
|
|
|
# enough in the past that I'm keeping it here until tests are better |
85
|
7
|
|
|
|
|
331
|
my $perl = "{\n \$$package\::DIST\x20=\x20'$dist_name';\n}\n"; |
86
|
|
|
|
|
|
|
|
87
|
7
|
|
|
|
|
33
|
my $dist_doc = PPI::Document->new(\$perl); |
88
|
7
|
|
|
|
|
13100
|
my @children = $dist_doc->schildren; |
89
|
|
|
|
|
|
|
|
90
|
7
|
|
|
|
|
90
|
$self->log_debug([ |
91
|
|
|
|
|
|
|
'adding $DIST assignment to %s in %s', |
92
|
|
|
|
|
|
|
$package, |
93
|
|
|
|
|
|
|
$file->name, |
94
|
|
|
|
|
|
|
]); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# the extra whitespace element ensures we don't swallow up any blanks |
97
|
|
|
|
|
|
|
# lines after 'package ...' in the source file that PkgVersion warns about |
98
|
|
|
|
|
|
|
# if it's missing. |
99
|
7
|
50
|
33
|
|
|
212
|
Carp::carp('error inserting $DIST in ' . $file->name) |
|
|
|
33
|
|
|
|
|
100
|
|
|
|
|
|
|
unless $stmt->add_element( PPI::Token::Whitespace->new("\n") ) |
101
|
|
|
|
|
|
|
and $stmt->insert_after($children[0]->clone) |
102
|
|
|
|
|
|
|
and $stmt->insert_after( PPI::Token::Whitespace->new("\n") ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# the document is no longer correct; it must be reparsed before it can be used again |
106
|
5
|
|
|
|
|
1251
|
$file->content($document->serialize); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=pod |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=encoding UTF-8 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 NAME |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Dist::Zilla::Plugin::PkgDist - add a $DIST to your packages |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 VERSION |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
version 6.030 |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 DESCRIPTION |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This plugin will add a line like the following to each package in each Perl |
129
|
|
|
|
|
|
|
module or program (more or less) within the distribution: |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
{ our $DIST = 'My-CPAN-Dist'; } # where 'My-CPAN-Dist' is your dist name |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
It will skip any package declaration that includes a newline between the |
134
|
|
|
|
|
|
|
C<package> keyword and the package name, like: |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
package |
137
|
|
|
|
|
|
|
Foo::Bar; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This sort of declaration is also ignored by the CPAN toolchain, and is |
140
|
|
|
|
|
|
|
typically used when doing monkey patching or other tricky things. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 PERL VERSION |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
This module should work on any version of perl still receiving updates from |
145
|
|
|
|
|
|
|
the Perl 5 Porters. This means it should work on any version of perl released |
146
|
|
|
|
|
|
|
in the last two to three years. (That is, if the most recently released |
147
|
|
|
|
|
|
|
version is v5.40, then this module should work on both v5.40 and v5.38.) |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Although it may work on older versions of perl, no guarantee is made that the |
150
|
|
|
|
|
|
|
minimum required version will not be increased. The version may be increased |
151
|
|
|
|
|
|
|
for any reason, and there is no promise that patches will be accepted to lower |
152
|
|
|
|
|
|
|
the minimum required perl. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 AUTHOR |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Ricardo SIGNES 😏 <cpan@semiotic.systems> |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This software is copyright (c) 2023 by Ricardo SIGNES. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
163
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |