{
my
$search
=
qr/
(?:^|\n) # After the beginning of the string, or a newline
( # ... start capturing
# EITHER
package\s+ # A package
[^\W\d]\w*(?:(?:\'|::)[^\W\d]\w*)* # ... with a name
\s*; # And a statement terminator
| # OR
\#\s*PODNAME:\s+ # A PODNAME comment
[^\W\d]\w*(?:(?:\'|::)[^\W\d]\w*)* # ... with a name
(?:\s+|$) # And a name terminator
|
=head1[ \t]+SYNOPSIS\n
.*?
(?=\n=)
| # OR
=for[ \t]+example[ \t]+begin\n # ... when we find a =for example begin
.*? # ... and keep capturing
\n=for[ \t]+example[ \t]+end\s*? # ... until the =for example end
(?:\n|$) # ... at the end of file or a newline
| # OR
=begin[ \t]+(?:test|testing)(?:-SETUP)? # ... when we find a =begin test or testing
.*? # ... and keep capturing
\n=end[ \t]+(?:test|testing)(?:-SETUP)? # ... until an =end tag
.*?
(?:\n|$) # ... at the end of file or a newline
) # ... and stop capturing
/
isx;
sub
_elements {
my
$self
=
shift
;
my
@elements
= ();
while
(
$self
->{source} =~ m/
$search
/go ) {
my
$elt
= $1;
if
(
$elt
=~ s/=head1[ \t]+SYNOPSIS/=begin testing-SETUP\n\n{/ ) {
$elt
.=
"}\n\n=end testing-SETUP"
;
}
$elt
=~ s/testing-SETUP/testing SETUP/g;
push
@elements
,
$elt
;
}
return
unless
@elements
> 2;
if
(
@elements
&&
$self
->{source} =~ /
foreach
my
$element
(
@elements
)
{
$element
=
"package $1;"
if
$element
=~ /
}
}
if
(
@elements
&&
$self
->{source} =~ /=head1 NAME\n\n(Moose::Cookbook\S+)/ ) {
unshift
@elements
,
'package '
. $1 .
';'
;
}
( first {/^=/}
@elements
) ? \
@elements
:
''
;
}
}
{
sub
process {
my
$self
=
shift
;
my
$base
=
$self
->SUPER::process(
@_
);
return
$base
;
}
}
1;