| 1 | package MooX::Purple::G; | ||||||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 9 | our $VERSION = '0.19'; | |||||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use PPR; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Perl::Tidy; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use Cwd qw/abs_path/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 9 | our %POD; | |||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 9 | our (%HAS, $GATTRS, $SATTRS, $PATTRS, $PREFIX, %MACROS, $DIST_VERSION, $AUTHOR, $AUTHOR_EMAIL); | |||||||||||||||||||||||||||||||
| 12 | 9 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 9 | $DIST_VERSION = '-version'; | |||||||||||||||||||||||||||||||
| 14 | 9 | $AUTHOR = '-author'; | |||||||||||||||||||||||||||||||
| 15 | 9 | $AUTHOR_EMAIL = '-author'; | |||||||||||||||||||||||||||||||
| 16 | 9 | $GATTRS = '( | |||||||||||||||||||||||||||||||
| 17 | allow (?&PerlNWS) | ||||||||||||||||||||||||||||||||
| 18 | (?:(?!qw)(?&PerlQualifiedIdentifier)| | ||||||||||||||||||||||||||||||||
| 19 | (?&PerlList)) | ||||||||||||||||||||||||||||||||
| 20 | | | ||||||||||||||||||||||||||||||||
| 21 | with (?&PerlNWS) | ||||||||||||||||||||||||||||||||
| 22 | (?:(?!qw)(?&PerlPrefixUnaryOperator)*(?&PerlQualifiedIdentifier)| | ||||||||||||||||||||||||||||||||
| 23 | (?&PerlList)) | ||||||||||||||||||||||||||||||||
| 24 | | | ||||||||||||||||||||||||||||||||
| 25 | is (?&PerlNWS) | ||||||||||||||||||||||||||||||||
| 26 | (?:(?!qw)(?&PerlPrefixUnaryOperator)*(?&PerlQualifiedIdentifier)| | ||||||||||||||||||||||||||||||||
| 27 | (?&PerlList)) | ||||||||||||||||||||||||||||||||
| 28 | | | ||||||||||||||||||||||||||||||||
| 29 | use (?&PerlNWS) | ||||||||||||||||||||||||||||||||
| 30 | (?:(?&PerlQualifiedIdentifier)\s*(?&PerlList)|(?:(?!qw)(?&PerlQualifiedIdentifier)| | ||||||||||||||||||||||||||||||||
| 31 | (?&PerlList))) | ||||||||||||||||||||||||||||||||
| 32 | | | ||||||||||||||||||||||||||||||||
| 33 | (?:(?&PerlNWS)*) | ||||||||||||||||||||||||||||||||
| 34 | )'; | ||||||||||||||||||||||||||||||||
| 35 | 9 | $SATTRS = '( | |||||||||||||||||||||||||||||||
| 36 | allow (?&PerlNWS) | ||||||||||||||||||||||||||||||||
| 37 | (?:(?!qw)(?&PerlQualifiedIdentifier)| | ||||||||||||||||||||||||||||||||
| 38 | (?&PerlList)) | ||||||||||||||||||||||||||||||||
| 39 | | | ||||||||||||||||||||||||||||||||
| 40 | (?:(?&PerlNWS)*) | ||||||||||||||||||||||||||||||||
| 41 | )'; | ||||||||||||||||||||||||||||||||
| 42 | 9 | $PATTRS = '( | |||||||||||||||||||||||||||||||
| 43 | describe (?&PerlNWS) | ||||||||||||||||||||||||||||||||
| 44 | (?:(?&PerlString)) | ||||||||||||||||||||||||||||||||
| 45 | | | ||||||||||||||||||||||||||||||||
| 46 | (?:(?&PerlNWS)*) | ||||||||||||||||||||||||||||||||
| 47 | )'; | ||||||||||||||||||||||||||||||||
| 48 | 9 | %HAS = ( | |||||||||||||||||||||||||||||||
| 49 | ro => '"ro"', | ||||||||||||||||||||||||||||||||
| 50 | ro => '"ro"', | ||||||||||||||||||||||||||||||||
| 51 | is_ro => 'is => "ro"', | ||||||||||||||||||||||||||||||||
| 52 | rw => '"rw"', | ||||||||||||||||||||||||||||||||
| 53 | is_rw => 'is => "rw"', | ||||||||||||||||||||||||||||||||
| 54 | nan => 'undef', | ||||||||||||||||||||||||||||||||
| 55 | lzy => 'lazy => 1', | ||||||||||||||||||||||||||||||||
| 56 | bld => 'builder => 1', | ||||||||||||||||||||||||||||||||
| 57 | lzy_bld => 'lazy_build => 1', | ||||||||||||||||||||||||||||||||
| 58 | trg => 'trigger => 1', | ||||||||||||||||||||||||||||||||
| 59 | clr => 'clearer => 1', | ||||||||||||||||||||||||||||||||
| 60 | req => 'required => 1', | ||||||||||||||||||||||||||||||||
| 61 | coe => 'coerce => 1', | ||||||||||||||||||||||||||||||||
| 62 | lzy_hash => 'lazy => 1, default => sub { {} }', | ||||||||||||||||||||||||||||||||
| 63 | lzy_array => 'lazy => 1, default => sub { [] }', | ||||||||||||||||||||||||||||||||
| 64 | lzy_str => 'lazy => 1, default => sub { "" }', | ||||||||||||||||||||||||||||||||
| 65 | dhash => 'default => sub { {} }', | ||||||||||||||||||||||||||||||||
| 66 | darray => 'default => sub { [] }', | ||||||||||||||||||||||||||||||||
| 67 | dstr => 'default => sub { "" }', | ||||||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||||||
| 69 | 9 | $HAS{compile_regex} = sprintf q|[\[\s]+(%s)[\s,]+|, join '|', keys %HAS; | |||||||||||||||||||||||||||||||
| 70 | 9 | $HAS{compile_value_regex} = sprintf q|[\[\s]+(%s)[\s,]+|, join '|', map { quotemeta($_) } | |||||||||||||||||||||||||||||||
| 71 | qw/default lazy required trigger clearer coerce handles builder predicate reader writer weak_ref init_arg moosify/; | ||||||||||||||||||||||||||||||||
| 72 | }; | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 245 | ▶ | sub g { | ||||||||||||||||||||||||||||||
|
Subroutine
g: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 75 | 245 | my ($source, $keyword, $callback, $lib, $pod) = @_; | |||||||||||||||||||||||||||||||
| 76 | 245 | ▶ | while ($$source =~ m/ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 77 | $keyword | ||||||||||||||||||||||||||||||||
| 78 | $PPR::GRAMMAR | ||||||||||||||||||||||||||||||||
| 79 | /xms) { | ||||||||||||||||||||||||||||||||
| 80 | 105 | my %hack = %+; | |||||||||||||||||||||||||||||||
| 81 | 105 | $hack{generate_pod} = $pod; | |||||||||||||||||||||||||||||||
| 82 | 105 | my ($make, %makes) = $callback->(%hack); | |||||||||||||||||||||||||||||||
| 83 | 105 | $hack{match} = quotemeta($hack{match}); | |||||||||||||||||||||||||||||||
| 84 | 105 | ▶ | if ($lib) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 85 | 26 | $make =~ s/(^\{\s*)|(\}\s*$)//g; | |||||||||||||||||||||||||||||||
| 86 | 26 | $make =~ s/^\t//gm; | |||||||||||||||||||||||||||||||
| 87 | 26 | $make .= render_pod($makes{class}); | |||||||||||||||||||||||||||||||
| 88 | write_file(sprintf("%s/%s.pmc", $lib, $makes{class}), $make) | ||||||||||||||||||||||||||||||||
| 89 | 26 | ▶ | if $makes{class}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 90 | 26 | $$source =~ s/$hack{match}//; | |||||||||||||||||||||||||||||||
| 91 | } else { | ||||||||||||||||||||||||||||||||
| 92 | 79 | $$source =~ s/$hack{match}/$make/e; | |||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||
| 95 | 245 | $source; | |||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 26 | ▶ | sub p { | ||||||||||||||||||||||||||||||
|
Subroutine
p: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 99 | 26 | g( | |||||||||||||||||||||||||||||||
| 100 | g( | ||||||||||||||||||||||||||||||||
| 101 | g( | ||||||||||||||||||||||||||||||||
| 102 | g( | ||||||||||||||||||||||||||||||||
| 103 | g( | ||||||||||||||||||||||||||||||||
| 104 | g( | ||||||||||||||||||||||||||||||||
| 105 | g( | ||||||||||||||||||||||||||||||||
| 106 | g( | ||||||||||||||||||||||||||||||||
| 107 | $_[0], | ||||||||||||||||||||||||||||||||
| 108 | qq|(?<match>start\\s* | ||||||||||||||||||||||||||||||||
| 109 | (?<method>(?&PerlIdentifier))\\s* | ||||||||||||||||||||||||||||||||
| 110 | (?<block>(?&PerlBlock)))|, | ||||||||||||||||||||||||||||||||
| 111 | \&start | ||||||||||||||||||||||||||||||||
| 112 | ), | ||||||||||||||||||||||||||||||||
| 113 | qq|(?<match>end\\s* | ||||||||||||||||||||||||||||||||
| 114 | (?<method>(?&PerlIdentifier))\\s* | ||||||||||||||||||||||||||||||||
| 115 | (?<block>(?&PerlBlock)))|, | ||||||||||||||||||||||||||||||||
| 116 | \&end | ||||||||||||||||||||||||||||||||
| 117 | ), | ||||||||||||||||||||||||||||||||
| 118 | qq|(?<match>during\\s* | ||||||||||||||||||||||||||||||||
| 119 | (?<method>(?&PerlIdentifier))\\s* | ||||||||||||||||||||||||||||||||
| 120 | (?<block>(?&PerlBlock)))|, | ||||||||||||||||||||||||||||||||
| 121 | \&during | ||||||||||||||||||||||||||||||||
| 122 | ), | ||||||||||||||||||||||||||||||||
| 123 | qq|(?<match>trigger\\s* | ||||||||||||||||||||||||||||||||
| 124 | (?<method>(?&PerlIdentifier))\\s* | ||||||||||||||||||||||||||||||||
| 125 | (?<block>(?&PerlBlock)))|, | ||||||||||||||||||||||||||||||||
| 126 | \&trigger | ||||||||||||||||||||||||||||||||
| 127 | ), | ||||||||||||||||||||||||||||||||
| 128 | qq|(?<match>macro\\s* | ||||||||||||||||||||||||||||||||
| 129 | (?<macro> (?&PerlIdentifier))\\s* | ||||||||||||||||||||||||||||||||
| 130 | (?<block> (?&PerlBlock));\n*)|, | ||||||||||||||||||||||||||||||||
| 131 | \¯o | ||||||||||||||||||||||||||||||||
| 132 | ), | ||||||||||||||||||||||||||||||||
| 133 | qq|(?<match> private\\s* | ||||||||||||||||||||||||||||||||
| 134 | (?<method> (?&PerlIdentifier)) | ||||||||||||||||||||||||||||||||
| 135 | (?<attrs> (?: $SATTRS*)) | ||||||||||||||||||||||||||||||||
| 136 | (?<block> (?&PerlBlock)))|, | ||||||||||||||||||||||||||||||||
| 137 | \&private, | ||||||||||||||||||||||||||||||||
| 138 | ), | ||||||||||||||||||||||||||||||||
| 139 | qq|(?<match> public\\s* | ||||||||||||||||||||||||||||||||
| 140 | (?<method> (?&PerlIdentifier)) | ||||||||||||||||||||||||||||||||
| 141 | (?:(?&PerlNWS))* | ||||||||||||||||||||||||||||||||
| 142 | (?<block> (?&PerlBlock)) | ||||||||||||||||||||||||||||||||
| 143 | (?<pod> (?: $PATTRS*)))|, | ||||||||||||||||||||||||||||||||
| 144 | \&public, | ||||||||||||||||||||||||||||||||
| 145 | undef, | ||||||||||||||||||||||||||||||||
| 146 | $_[1] | ||||||||||||||||||||||||||||||||
| 147 | ), | ||||||||||||||||||||||||||||||||
| 148 | qq|(?<match> attributes\\s* (?<list> (?&PerlList))\\s*\;)|, | ||||||||||||||||||||||||||||||||
| 149 | \&attributes | ||||||||||||||||||||||||||||||||
| 150 | ); | ||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | 49 | ▶ | sub i { | ||||||||||||||||||||||||||||||
|
Subroutine
i: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 154 | 49 | my $i = shift; | |||||||||||||||||||||||||||||||
| 155 | 49 | my @s; | |||||||||||||||||||||||||||||||
| 156 | 49 | ▶ | while ( $i =~ s/ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 157 | (?<match>\s*(?: | ||||||||||||||||||||||||||||||||
| 158 | (?<hash>\s*(?&PerlAnonymousHash))| | ||||||||||||||||||||||||||||||||
| 159 | (?<array>\s*(?&PerlAnonymousArray))| | ||||||||||||||||||||||||||||||||
| 160 | (?<sub>\s*(?&PerlAnonymousSubroutine))| | ||||||||||||||||||||||||||||||||
| 161 | (?<bless>\s*(bless\s*(?&PerlExpression)))| | ||||||||||||||||||||||||||||||||
| 162 | (?<ident>\s*(?&PerlIdentifier))| | ||||||||||||||||||||||||||||||||
| 163 | (?<string>\s*(?&PerlString))| | ||||||||||||||||||||||||||||||||
| 164 | (?<num>\s*(?&PerlNumber)) | ||||||||||||||||||||||||||||||||
| 165 | )+)\s*(?&PerlComma)* | ||||||||||||||||||||||||||||||||
| 166 | $PPR::GRAMMAR | ||||||||||||||||||||||||||||||||
| 167 | //xms ) { | ||||||||||||||||||||||||||||||||
| 168 | 66 | push @s, {%+} | |||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||
| 170 | 49 | return @s; | |||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | 24 | ▶ | sub r { | ||||||||||||||||||||||||||||||
|
Subroutine
r: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 174 | 24 | my $i = shift; | |||||||||||||||||||||||||||||||
| 175 | 24 | ▶ | while ($i =~ m/$_[0]/xms) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 176 | 13 | my $m = $1; | |||||||||||||||||||||||||||||||
| 177 | 13 | $i =~ s/$m/$_[1]->{$m}/; | |||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||
| 179 | 24 | $i; | |||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||
| 182 | 4 | ▶ | sub kv { | ||||||||||||||||||||||||||||||
|
Subroutine
kv: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 183 | 4 | my ($i, %a) = @_; | |||||||||||||||||||||||||||||||
| 184 | 4 | ▶ | while ( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 185 | $i =~ s/ | ||||||||||||||||||||||||||||||||
| 186 | \s*(?<key> (?&PerlTerm))\s* | ||||||||||||||||||||||||||||||||
| 187 | (?&PerlComma) | ||||||||||||||||||||||||||||||||
| 188 | \s*(?<value> (?&PerlTerm))\s* | ||||||||||||||||||||||||||||||||
| 189 | $PPR::GRAMMAR | ||||||||||||||||||||||||||||||||
| 190 | //xms | ||||||||||||||||||||||||||||||||
| 191 | ) { | ||||||||||||||||||||||||||||||||
| 192 | 6 | my %h = %+; | |||||||||||||||||||||||||||||||
| 193 | 6 | $h{key} =~ s/(^\s*)|(\s*$)//g; | |||||||||||||||||||||||||||||||
| 194 | 6 | $a{$h{key}} = $h{value}; | |||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||
| 196 | 4 | return %a; | |||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | 11 | ▶ | sub import { | ||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=6 SCAR=18.4
| |||||||||||||||||||||||||||||||||
| 200 | 11 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||
| 201 | 11 | ▶ | $PREFIX = $args{-prefix} unless $PREFIX; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 202 | 11 | ▶ | if ($args{-author}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 203 | 1 | $args{-author} =~ m/(.*)\s*\<(.*)\>/; | |||||||||||||||||||||||||||||||
| 204 | 1 | $AUTHOR_EMAIL = $2; | |||||||||||||||||||||||||||||||
| 205 | 1 | ($AUTHOR = $1) =~ s/\s$//; | |||||||||||||||||||||||||||||||
| 206 | 1 | $AUTHOR_EMAIL =~ s/\@/ at /; | |||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||
| 208 | 11 | ▶ | $DIST_VERSION = $args{-version} if $args{-version}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 209 | 11 | my $lib = $args{-lib}; | |||||||||||||||||||||||||||||||
| 210 | 11 | ▶ | my $file = $args{-module} ? [caller(1)]->[1] : $0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 211 | 11 | open FH, "<$file"; | |||||||||||||||||||||||||||||||
| 212 | 11 | my $source = \join '', <FH>; | |||||||||||||||||||||||||||||||
| 213 | 11 | close FH; | |||||||||||||||||||||||||||||||
| 214 | 11 | g( | |||||||||||||||||||||||||||||||
| 215 | g( | ||||||||||||||||||||||||||||||||
| 216 | g( | ||||||||||||||||||||||||||||||||
| 217 | $source, | ||||||||||||||||||||||||||||||||
| 218 | qq/(?<match>(?&PerlPod))/, | ||||||||||||||||||||||||||||||||
| 219 | \&parse_pod | ||||||||||||||||||||||||||||||||
| 220 | ), | ||||||||||||||||||||||||||||||||
| 221 | qq/(?<match> role\\s* | ||||||||||||||||||||||||||||||||
| 222 | (?<class>(?&PerlPrefixUnaryOperator)*(?&PerlQualifiedIdentifier)) | ||||||||||||||||||||||||||||||||
| 223 | (?<attrs> (?: $GATTRS*)) | ||||||||||||||||||||||||||||||||
| 224 | (?<block> (?&PerlBlock)))/, | ||||||||||||||||||||||||||||||||
| 225 | \&roles, | ||||||||||||||||||||||||||||||||
| 226 | $lib | ||||||||||||||||||||||||||||||||
| 227 | ), | ||||||||||||||||||||||||||||||||
| 228 | qq/(?<match> class\\s* | ||||||||||||||||||||||||||||||||
| 229 | (?<class>(?&PerlPrefixUnaryOperator)*(?&PerlQualifiedIdentifier)) | ||||||||||||||||||||||||||||||||
| 230 | (?<attrs> (?: $GATTRS*)) | ||||||||||||||||||||||||||||||||
| 231 | (?<block> (?&PerlBlock)))/, | ||||||||||||||||||||||||||||||||
| 232 | \&classes, | ||||||||||||||||||||||||||||||||
| 233 | $lib | ||||||||||||||||||||||||||||||||
| 234 | ); | ||||||||||||||||||||||||||||||||
| 235 | 11 | ▶ | unless ($lib) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 236 | 0 | $source =~ s/use MooX\:\:Purple;\n*//; | |||||||||||||||||||||||||||||||
| 237 | 0 | $source =~ s/use MooX\:\:Purple\:\:G;\n*//; | |||||||||||||||||||||||||||||||
| 238 | 0 | my $current = [caller()]->[1]; | |||||||||||||||||||||||||||||||
| 239 | 0 | $current =~ s/\.(.*)/\.pmc/; | |||||||||||||||||||||||||||||||
| 240 | 0 | write_file($current, $$source); | |||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||
| 244 | 26 | ▶ | sub make_path { | ||||||||||||||||||||||||||||||
|
Subroutine
make_path: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 245 | 26 | my $path = abs_path();; | |||||||||||||||||||||||||||||||
| 246 | 26 | for (split '/', $_[0]) { | |||||||||||||||||||||||||||||||
| 247 | 77 | $path .= "/$_"; | |||||||||||||||||||||||||||||||
| 248 | 77 | ▶ | if (! -d $path) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 249 | 5 | ▶ | mkdir $path or Carp::croak(qq/ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 250 | Cannot open file for writing $! | ||||||||||||||||||||||||||||||||
| 251 | /); | ||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||
| 256 | 26 | ▶ | sub write_file { | ||||||||||||||||||||||||||||||
|
Subroutine
write_file: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 257 | 26 | my $f = $_[0]; | |||||||||||||||||||||||||||||||
| 258 | 26 | $f =~ s/\:\:/\//g; | |||||||||||||||||||||||||||||||
| 259 | 26 | make_path(substr($f, 0, rindex($f, '/'))); | |||||||||||||||||||||||||||||||
| 260 | 26 | ▶ | open FH, '>', $f or die "$f cannot open file to write $!"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 261 | 26 | print FH perl_tidy($_[1]); | |||||||||||||||||||||||||||||||
| 262 | 26 | close FH; | |||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||
| 265 | 2 | ▶ | sub macro { | ||||||||||||||||||||||||||||||
|
Subroutine
macro: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 266 | 2 | my %args = @_; | |||||||||||||||||||||||||||||||
| 267 | 2 | $args{block} =~ s/^\n*\{\n*\s*|;\n*\t*\}\n*$//g; | |||||||||||||||||||||||||||||||
| 268 | 2 | $MACROS{$args{macro}} = $args{block}; | |||||||||||||||||||||||||||||||
| 269 | 2 | return ''; | |||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||
| 272 | 1 | ▶ | sub start { | ||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 273 | 1 | push @_, pre => '-'; | |||||||||||||||||||||||||||||||
| 274 | 1 | when(@_); | |||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||
| 277 | 1 | ▶ | sub end { | ||||||||||||||||||||||||||||||
|
Subroutine
end: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 278 | 1 | push @_, pre => '+'; | |||||||||||||||||||||||||||||||
| 279 | 1 | when(@_); | |||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||
| 282 | 1 | ▶ | sub during { | ||||||||||||||||||||||||||||||
|
Subroutine
during: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 283 | 1 | push @_, pre => '~'; | |||||||||||||||||||||||||||||||
| 284 | 1 | when(@_); | |||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||
| 287 | 1 | ▶ | sub trigger { | ||||||||||||||||||||||||||||||
|
Subroutine
trigger: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 288 | 1 | push @_, pre => '='; | |||||||||||||||||||||||||||||||
| 289 | 1 | when(@_); | |||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||
| 292 | 4 | ▶ | sub when { | ||||||||||||||||||||||||||||||
|
Subroutine
when: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 293 | 4 | my %args = @_; | |||||||||||||||||||||||||||||||
| 294 | 4 | my %map = ( | |||||||||||||||||||||||||||||||
| 295 | '-' => 'before', | ||||||||||||||||||||||||||||||||
| 296 | '+' => 'after', | ||||||||||||||||||||||||||||||||
| 297 | '~' => 'around', | ||||||||||||||||||||||||||||||||
| 298 | '=' => 'around' | ||||||||||||||||||||||||||||||||
| 299 | ); | ||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||
| 301 | 4 | $args{block} =~ s/(^{)|(}$)//g; | |||||||||||||||||||||||||||||||
| 302 | 4 | ▶ | if ($args{pre} eq '~') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 303 | 1 | $args{block} = "{ | |||||||||||||||||||||||||||||||
| 304 | my (\$orig, \$self) = (shift, shift); | ||||||||||||||||||||||||||||||||
| 305 | $args{block}; | ||||||||||||||||||||||||||||||||
| 306 | }"; | ||||||||||||||||||||||||||||||||
| 307 | } elsif ($args{pre} eq '=') { | ||||||||||||||||||||||||||||||||
| 308 | 1 | $args{block} = "{ | |||||||||||||||||||||||||||||||
| 309 | my (\$orig, \$self) = (shift, shift); | ||||||||||||||||||||||||||||||||
| 310 | my \$out = \$self->\$orig(\@_); | ||||||||||||||||||||||||||||||||
| 311 | $args{block}; | ||||||||||||||||||||||||||||||||
| 312 | }"; | ||||||||||||||||||||||||||||||||
| 313 | } else { | ||||||||||||||||||||||||||||||||
| 314 | 2 | $args{block} = "{ | |||||||||||||||||||||||||||||||
| 315 | my (\$self) = (shift); | ||||||||||||||||||||||||||||||||
| 316 | $args{block}; | ||||||||||||||||||||||||||||||||
| 317 | }"; | ||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||
| 319 | 4 | return "$map{$args{pre}} $args{method} => sub $args{block};"; | |||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||
| 322 | 4 | ▶ | sub attributes { | ||||||||||||||||||||||||||||||
|
Subroutine
attributes: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 323 | 4 | my %args = @_; | |||||||||||||||||||||||||||||||
| 324 | 4 | my @attr; | |||||||||||||||||||||||||||||||
| 325 | g( | ||||||||||||||||||||||||||||||||
| 326 | \$args{list}, | ||||||||||||||||||||||||||||||||
| 327 | qq/(?<match> | ||||||||||||||||||||||||||||||||
| 328 | \\s*(?<key> (?&PerlTerm))\\s* | ||||||||||||||||||||||||||||||||
| 329 | (?&PerlComma) | ||||||||||||||||||||||||||||||||
| 330 | \\s*(?<value> (?&PerlTerm))\\s* | ||||||||||||||||||||||||||||||||
| 331 | )/, | ||||||||||||||||||||||||||||||||
| 332 | 24 | ▶ | sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 333 | 24 | my %hack = _construct_attribute(@_); | |||||||||||||||||||||||||||||||
| 334 | 24 | $hack{key} =~ m/\s*(?<array> (?&PerlAnonymousArray)) $PPR::GRAMMAR/xms; | |||||||||||||||||||||||||||||||
| 335 | 24 | ▶ | for my $key ( ($+{array} ? @{ eval $+{array} } : $hack{key}) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 336 | 29 | $key =~ s/(^\s*)|(\s*$)//g; | |||||||||||||||||||||||||||||||
| 337 | push @attr, sprintf( | ||||||||||||||||||||||||||||||||
| 338 | q/has %s => ( | ||||||||||||||||||||||||||||||||
| 339 | %s | ||||||||||||||||||||||||||||||||
| 340 | );/, | ||||||||||||||||||||||||||||||||
| 341 | $key, join( ",\n\t", (map { | ||||||||||||||||||||||||||||||||
| 342 | 36 | $hack{$_} =~ s/(["']+)/"/g; | |||||||||||||||||||||||||||||||
| 343 | 36 | qq/\t$_ => $hack{$_}/ | |||||||||||||||||||||||||||||||
| 344 | 174 | } grep { defined $hack{$_} } qw/is isa trigger builder lazy clearer/), (map { | |||||||||||||||||||||||||||||||
| 345 | 25 | my $hak = [i($hack{$_})]->[0]; | |||||||||||||||||||||||||||||||
| 346 | 25 | ▶ | $hack{$_} = defined $hak->{sub} ? $hak->{sub} : qq/sub { $hack{$_} }/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 347 | 25 | qq/\t$_ => $hack{$_}/; | |||||||||||||||||||||||||||||||
| 348 | 29 | } grep { $hack{$_} } qw/default/))); | |||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||
| 351 | 4 | ); | |||||||||||||||||||||||||||||||
| 352 | 4 | return join "\n\n", @attr; | |||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||
| 355 | 24 | ▶ | sub _construct_attribute { | ||||||||||||||||||||||||||||||
|
Subroutine
_construct_attribute: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||
| 356 | 24 | my (%attr) = @_; | |||||||||||||||||||||||||||||||
| 357 | 24 | $attr{value} = r($attr{value}, $HAS{compile_regex}, \%HAS); | |||||||||||||||||||||||||||||||
| 358 | 24 | $attr{value} =~ s/(^\s*\[)|(\s*\]$)//g; | |||||||||||||||||||||||||||||||
| 359 | 24 | my @spec = i($attr{value}); | |||||||||||||||||||||||||||||||
| 360 | 24 | my $oc = scalar @spec; | |||||||||||||||||||||||||||||||
| 361 | 24 | ▶ | unshift @spec, { string => '"ro"' } if (!$spec[0]->{string}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 362 | $attr{is} = $spec[0]->{string} =~ m/[\'\"\s]+(ro|rw)[\'\"\s]+/ | ||||||||||||||||||||||||||||||||
| 363 | ? shift(@spec)->{string} | ||||||||||||||||||||||||||||||||
| 364 | 24 | ▶ | : '"ro"'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 365 | ($spec[0]->{ident} eq 'undef') | ||||||||||||||||||||||||||||||||
| 366 | ? shift(@spec) | ||||||||||||||||||||||||||||||||
| 367 | : do { | ||||||||||||||||||||||||||||||||
| 368 | 1 | $attr{isa} = shift(@spec)->{ident}; | |||||||||||||||||||||||||||||||
| 369 | 24 | ▶ | } if $spec[0]->{ident}; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 370 | 24 | ▶ | my $attrHash = $spec[0]->{hash} ? $spec[0]->{match} =~ m/$HAS{compile_value_regex}/g : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 371 | 24 | ▶ | if ($spec[0] && keys %{$spec[0]}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$spec[0] and keys %{$spec[0];}
MC/DC50%1/2
$spec[0] and keys %{$spec[0];}
$spec[0]
keys %{$spec[0];}
Truth table66%2/3
A and B
A= $spec[0]B= keys %{$spec[0];}
| |||||||||||||||||||||||||||||||||
| 372 | 22 | ▶ | $attr{default} = !$attrHash && $oc <= 3 ? $spec[0]->{sub} ? shift(@spec)->{sub} : qq/sub { / . shift(@spec)->{match} . qq/ }/ : ''; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
not $attrHash and $oc <= 3
MC/DC50%1/2
not $attrHash and $oc <= 3
not $attrHash
$oc <= 3
Truth table66%2/3
not(A) and B
A= not $attrHashB= $oc <= 3
| |||||||||||||||||||||||||||||||||
| 373 | 22 | ▶ | %attr = kv($spec[0]->{match}, %attr) if ($spec[0]); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||
| 375 | 24 | delete $attr{value}; | |||||||||||||||||||||||||||||||
| 376 | 24 | return %attr; | |||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||
| 379 | 12 | ▶ | sub roles { | ||||||||||||||||||||||||||||||
|
Subroutine
roles: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 380 | 12 | my %args = @_; | |||||||||||||||||||||||||||||||
| 381 | 12 | ▶ | my @hack = grep {$_ && $_ !~ m/^\s*$/} $args{attrs} =~ m/(?:$GATTRS) $PPR::GRAMMAR/gx; | ||||||||||||||||||||||||||||||
|
Condition100%3/3
$_ && !($_ =~ /^\s*$/)
MC/DC100%2/2
$_ && !($_ =~ /^\s*$/)
$_
!($_ =~ /^\s*$/)
Truth table100%3/3
A && not(B)
A= $_B= !($_ =~ /^\s*$/)
| |||||||||||||||||||||||||||||||||
| 382 | 12 | my ($body, %attrs) = _set_class_role_attrs($args{block}, _parse_role_attrs(@hack)); | |||||||||||||||||||||||||||||||
| 383 | 12 | $body =~ s/\s*$//; | |||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||
| 385 | 12 | $args{class} =~ s/^\+/$PREFIX\:\:/; | |||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||
| 387 | 12 | my $pod = prepare_pod($args{class}); | |||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||
| 389 | 12 | my $r = \qq|{ | |||||||||||||||||||||||||||||||
| 390 | package $args{class}; | ||||||||||||||||||||||||||||||||
| 391 | use Moo::Role; | ||||||||||||||||||||||||||||||||
| 392 | use MooX::LazierAttributes; | ||||||||||||||||||||||||||||||||
| 393 | use MooX::ValidateSubs; | ||||||||||||||||||||||||||||||||
| 394 | use Data::LnArray qw/arr/; | ||||||||||||||||||||||||||||||||
| 395 | $attrs{with}$attrs{use}$body | ||||||||||||||||||||||||||||||||
| 396 | 1; | ||||||||||||||||||||||||||||||||
| 397 | }|; | ||||||||||||||||||||||||||||||||
| 398 | 12 | p($r, !$pod); | |||||||||||||||||||||||||||||||
| 399 | 12 | return ($$r, %args); | |||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||
| 402 | 24 | ▶ | sub parse_pod { | ||||||||||||||||||||||||||||||
|
Subroutine
parse_pod: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 403 | 24 | my %h = @_; | |||||||||||||||||||||||||||||||
| 404 | 24 | ▶ | if ($h{match} =~ m/=head1 NAME\n*([^\s]+)/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 405 | 8 | $POD{$1} = $POD{CURRENT} = { PARSED => 1, DATA => [] }; | |||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||
| 407 | 24 | push @{$POD{CURRENT}{DATA}}, $h{match}; | |||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||
| 410 | 26 | ▶ | sub prepare_pod { | ||||||||||||||||||||||||||||||
|
Subroutine
prepare_pod: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 411 | 26 | my $class = shift; | |||||||||||||||||||||||||||||||
| 412 | 26 | ▶ | if (!$POD{$class}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 413 | 18 | $POD{$class} = $POD{CURRENT} = { PARSED => 0, DATA => [] }; | |||||||||||||||||||||||||||||||
| 414 | 18 | push @{$POD{$class}{DATA}}, " =head1 NAME | |||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||
| 416 | $class - The great new $class! | ||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||
| 418 | =cut"; | ||||||||||||||||||||||||||||||||
| 419 | 18 | push @{$POD{$class}{DATA}}, " =head1 Version | |||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||
| 421 | Version $DIST_VERSION | ||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||
| 423 | =cut"; | ||||||||||||||||||||||||||||||||
| 424 | 18 | push @{$POD{$class}{DATA}}, " =head1 SYNOPSIS | |||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||
| 426 | use $class; | ||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||
| 428 | $class\-\>new(\\%args) | ||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||
| 430 | =cut"; | ||||||||||||||||||||||||||||||||
| 431 | 18 | push @{$POD{$class}{DATA}}, " =head1 SUBROUTINES/METHODS | |||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||
| 433 | =cut"; | ||||||||||||||||||||||||||||||||
| 434 | 18 | return 0; | |||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||
| 436 | 8 | return 1; | |||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||
| 439 | 26 | ▶ | sub render_pod { | ||||||||||||||||||||||||||||||
|
Subroutine
render_pod: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 440 | 26 | my $class = shift; | |||||||||||||||||||||||||||||||
| 441 | 26 | ▶ | if ($POD{$class}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 442 | 26 | ▶ | if (!$POD{$class}{PARSED}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 443 | 18 | (my $url_class = $class) =~ s/\:\:/-/g; | |||||||||||||||||||||||||||||||
| 444 | 18 | push @{$POD{$class}{DATA}}, " =head1 AUTHOR | |||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||
| 446 | $AUTHOR, C<< <$AUTHOR_EMAIL> >> | ||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||
| 448 | =cut"; | ||||||||||||||||||||||||||||||||
| 449 | 18 | push @{$POD{$class}{DATA}}, " =head1 BUGS | |||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||
| 451 | Please report any bugs or feature requests to C<bug-moox-purple at rt.cpan.org>, or through | ||||||||||||||||||||||||||||||||
| 452 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=$url_class>. I will be notified, and then you'll | ||||||||||||||||||||||||||||||||
| 453 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||
| 455 | =cut"; | ||||||||||||||||||||||||||||||||
| 456 | 18 | push @{$POD{$class}{DATA}}, " =head1 SUPPORT | |||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||
| 458 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||
| 460 | perldoc $class | ||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||
| 463 | You can also look for information at: | ||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||
| 465 | =over 2 | ||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||
| 467 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||
| 469 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=$url_class> | ||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||
| 471 | =item * Search CPAN | ||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||
| 473 | L<http://search.cpan.org/dist/$url_class/> | ||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||
| 475 | =back | ||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||
| 477 | =cut"; | ||||||||||||||||||||||||||||||||
| 478 | 18 | push @{$POD{$class}{DATA}}, " =head1 ACKNOWLEDGEMENTS | |||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||
| 480 | =cut"; | ||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||
| 482 | 18 | push @{$POD{$class}{DATA}}, " =head1 LICENSE AND COPYRIGHT | |||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||
| 484 | Copyright 2025 $AUTHOR. | ||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||
| 486 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||
| 487 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||||||||||||||||||||||||
| 488 | copy of the full license at: | ||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||
| 490 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||
| 492 | Any use, modification, and distribution of the Standard or Modified | ||||||||||||||||||||||||||||||||
| 493 | Versions is governed by this Artistic License. By using, modifying or | ||||||||||||||||||||||||||||||||
| 494 | distributing the Package, you accept this license. Do not use, modify, | ||||||||||||||||||||||||||||||||
| 495 | or distribute the Package, if you do not accept this license. | ||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||
| 497 | If your Modified Version has been derived from a Modified Version made | ||||||||||||||||||||||||||||||||
| 498 | by someone other than you, you are nevertheless required to ensure that | ||||||||||||||||||||||||||||||||
| 499 | your Modified Version complies with the requirements of this license. | ||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||
| 501 | This license does not grant you the right to use any trademark, service | ||||||||||||||||||||||||||||||||
| 502 | mark, tradename, or logo of the Copyright Holder. | ||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||
| 504 | This license includes the non-exclusive, worldwide, free-of-charge | ||||||||||||||||||||||||||||||||
| 505 | patent license to make, have made, use, offer to sell, sell, import and | ||||||||||||||||||||||||||||||||
| 506 | otherwise transfer the Package with respect to any patent claims | ||||||||||||||||||||||||||||||||
| 507 | licensable by the Copyright Holder that are necessarily infringed by the | ||||||||||||||||||||||||||||||||
| 508 | Package. If you institute patent litigation (including a cross-claim or | ||||||||||||||||||||||||||||||||
| 509 | counterclaim) against any party alleging that the Package constitutes | ||||||||||||||||||||||||||||||||
| 510 | direct or contributory patent infringement, then this Artistic License | ||||||||||||||||||||||||||||||||
| 511 | to you shall terminate on the date that such litigation is filed. | ||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||
| 513 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||||||||||||||||||||||||||||||||
| 514 | AND CONTRIBUTORS 'AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||||||||||||||||||||||||||||||||
| 515 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||||||||||||||||||||||||||||||||
| 516 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||||||||||||||||||||||||||||||||
| 517 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||||||||||||||||||||||||||||||||
| 518 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||||||||||||||||||||||||||||||||
| 519 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||||||||||||||||||||||||||||||||
| 520 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||
| 522 | =cut"; | ||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||
| 525 | 26 | return join "\n", map { my $v = $_; $v =~ s/^\t//gm; $v; } @{$POD{$class}{DATA}}; | |||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||
| 527 | 0 | return ''; | |||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||
| 530 | 14 | ▶ | sub classes { | ||||||||||||||||||||||||||||||
|
Subroutine
classes: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 531 | 14 | my %args = @_; | |||||||||||||||||||||||||||||||
| 532 | 14 | ▶ | my @hack = grep {$_ && $_ !~ m/^\s*$/} $args{attrs} =~ m/(?:$GATTRS) $PPR::GRAMMAR/gx; | ||||||||||||||||||||||||||||||
|
Condition100%3/3
$_ && !($_ =~ /^\s*$/)
MC/DC100%2/2
$_ && !($_ =~ /^\s*$/)
$_
!($_ =~ /^\s*$/)
Truth table100%3/3
A && not(B)
A= $_B= !($_ =~ /^\s*$/)
| |||||||||||||||||||||||||||||||||
| 533 | 14 | my ($body, %attrs) = _set_class_role_attrs($args{block}, _parse_role_attrs(@hack)); | |||||||||||||||||||||||||||||||
| 534 | 14 | $body =~ s/\s*$//; | |||||||||||||||||||||||||||||||
| 535 | 14 | $args{class} =~ s/^\+/$PREFIX\:\:/; | |||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||
| 537 | 14 | my $pod = prepare_pod($args{class}); | |||||||||||||||||||||||||||||||
| 538 | 14 | my $r = \qq|{ | |||||||||||||||||||||||||||||||
| 539 | package $args{class}; | ||||||||||||||||||||||||||||||||
| 540 | use Moo; | ||||||||||||||||||||||||||||||||
| 541 | use MooX::LazierAttributes; | ||||||||||||||||||||||||||||||||
| 542 | use MooX::ValidateSubs; | ||||||||||||||||||||||||||||||||
| 543 | use Data::LnArray qw/arr/; | ||||||||||||||||||||||||||||||||
| 544 | $attrs{is}$attrs{with}$attrs{use}$body | ||||||||||||||||||||||||||||||||
| 545 | 1; | ||||||||||||||||||||||||||||||||
| 546 | }|; | ||||||||||||||||||||||||||||||||
| 547 | 14 | p($r, !$pod); | |||||||||||||||||||||||||||||||
| 548 | 14 | return ($$r, %args); | |||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||
| 551 | 21 | ▶ | sub macro_replacement { | ||||||||||||||||||||||||||||||
|
Subroutine
macro_replacement: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 552 | 21 | my $block = shift; | |||||||||||||||||||||||||||||||
| 553 | 21 | my $mac = join '|', keys %MACROS; | |||||||||||||||||||||||||||||||
| 554 | 21 | $block =~ s/&($mac)/$MACROS{$1}/g; | |||||||||||||||||||||||||||||||
| 555 | 21 | return $block; | |||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||
| 558 | 2 | ▶ | sub private { | ||||||||||||||||||||||||||||||
|
Subroutine
private: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 559 | 2 | my %args = @_; | |||||||||||||||||||||||||||||||
| 560 | 2 | ▶ | my @hack = grep {$_ && $_ !~ m/^\s*$/} $args{attrs} =~ m/(?:$SATTRS) $PPR::GRAMMAR/gx; | ||||||||||||||||||||||||||||||
|
Condition100%3/3
$_ && !($_ =~ /^\s*$/)
MC/DC100%2/2
$_ && !($_ =~ /^\s*$/)
$_
!($_ =~ /^\s*$/)
Truth table100%3/3
A && not(B)
A= $_B= !($_ =~ /^\s*$/)
| |||||||||||||||||||||||||||||||||
| 561 | 2 | my %attrs = _parse_role_attrs(@hack); | |||||||||||||||||||||||||||||||
| 562 | 2 | ▶ | my $allowed = $attrs{allow} ? sprintf 'qw(%s)', join ' ', @{$attrs{allow}} : 'qw//'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 563 | 2 | $args{block} = macro_replacement($args{block}); | |||||||||||||||||||||||||||||||
| 564 | 2 | $args{block} =~ s/(^{)|(}$)//g; | |||||||||||||||||||||||||||||||
| 565 | 2 | $args{block} =~ s/^\s*//; | |||||||||||||||||||||||||||||||
| 566 | 2 | return "sub $args{method} { | |||||||||||||||||||||||||||||||
| 567 | my (\$self) = shift; | ||||||||||||||||||||||||||||||||
| 568 | my \$caller = caller(); | ||||||||||||||||||||||||||||||||
| 569 | my \@allowed = $allowed; | ||||||||||||||||||||||||||||||||
| 570 | unless (\$caller eq __PACKAGE__ || grep { \$_ eq \$caller } \@allowed) { | ||||||||||||||||||||||||||||||||
| 571 | die \"cannot call private method $args{method} from \$caller\"; | ||||||||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||||||
| 573 | $args{block} | ||||||||||||||||||||||||||||||||
| 574 | }"; | ||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||
| 577 | 19 | ▶ | sub public { | ||||||||||||||||||||||||||||||
|
Subroutine
public: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 578 | 19 | my %args = @_; | |||||||||||||||||||||||||||||||
| 579 | 19 | ▶ | if ($args{pod}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 580 | 19 | $args{pod} =~ m/describe\s*(.*)/i; | |||||||||||||||||||||||||||||||
| 581 | 19 | $args{pod} = eval $1; | |||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||
| 583 | 19 | ▶ | $args{pod} //= ''; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"pod"} //= ""
MC/DC100%1/1
$args{"pod"} //= ""
$args{"pod"}
Truth table100%2/2
A
A= $args{"pod"}
| |||||||||||||||||||||||||||||||||
| 584 | 11 | push @{ $POD{CURRENT}{DATA} }, " =head2 $args{method} | |||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||
| 586 | $args{pod} | ||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||
| 588 | \$class->$args{method} | ||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||
| 590 | 19 | ▶ | =cut" if $args{generate_pod}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 591 | 19 | $args{block} = macro_replacement($args{block}); | |||||||||||||||||||||||||||||||
| 592 | 19 | $args{block} =~ s/(^{)|(}$)//g; | |||||||||||||||||||||||||||||||
| 593 | 19 | return "sub $args{method} { | |||||||||||||||||||||||||||||||
| 594 | my (\$self) = shift; | ||||||||||||||||||||||||||||||||
| 595 | $args{block} | ||||||||||||||||||||||||||||||||
| 596 | }"; | ||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||
| 599 | 28 | ▶ | sub _parse_role_attrs { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_role_attrs: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||
| 600 | 28 | my @roles = @_; | |||||||||||||||||||||||||||||||
| 601 | 28 | my %attrs; | |||||||||||||||||||||||||||||||
| 602 | 28 | my $i = 0; | |||||||||||||||||||||||||||||||
| 603 | 28 | for (@roles) { | |||||||||||||||||||||||||||||||
| 604 | 17 | ▶ | if ($_ =~ m/\s*use\s*((?!qw)(?&PerlQualifiedIdentifier))\s*((?&PerlList)) $PPR::GRAMMAR/xms) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 605 | 1 | $attrs{use}{sprintf "%s %s", $1, $2}++; | |||||||||||||||||||||||||||||||
| 606 | 1 | next; | |||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||
| 608 | 16 | $_ =~ m/(with|allow|is|use)(.*)/i; | |||||||||||||||||||||||||||||||
| 609 | 16 | my @list = eval($2); # || $2 | |||||||||||||||||||||||||||||||
| 610 | 16 | ▶ | push @list, do { (my $g = $2) =~ s/^\s*//; $g; } unless @list; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 611 | 16 | for (@list) { | |||||||||||||||||||||||||||||||
| 612 | 24 | $attrs{$1}{$_} = $i++; | |||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||
| 615 | 28 | for my $o (qw/with allow is use/) { | |||||||||||||||||||||||||||||||
| 616 | 112 | ▶ | $attrs{$o} = [sort { $attrs{$o}{$a} <=> $attrs{$o}{$b} } keys %{$attrs{$o}}] if $attrs{$o}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||
| 618 | 28 | return %attrs; | |||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||
| 621 | 26 | ▶ | sub _set_class_role_attrs { | ||||||||||||||||||||||||||||||
|
Subroutine
_set_class_role_attrs: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||
| 622 | 26 | my ($body, %attrs) = @_; | |||||||||||||||||||||||||||||||
| 623 | 26 | ▶ | if ($attrs{allow}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 624 | 2 | my $allow = join ' ', @{$attrs{allow}}; | |||||||||||||||||||||||||||||||
| 625 | 2 | $body =~ s{private\s*(\p{XIDS}\p{XIDC}*)}{private $1 allow qw/$allow/}g; | |||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||
| 627 | 26 | ▶ | $attrs{is} = $attrs{is} ? sprintf "extends qw/%s/;\n", join(' ', map { my $l = $_; $l =~ s/^\s*\+/$PREFIX\:\:/; $l; } @{$attrs{is}}) : ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 628 | 26 | my $last; | |||||||||||||||||||||||||||||||
| 629 | $attrs{with} = $attrs{with} | ||||||||||||||||||||||||||||||||
| 630 | ? sprintf "with qw/%s/;\n", join(' ', map { | ||||||||||||||||||||||||||||||||
| 631 | 14 | my $l = $_; | |||||||||||||||||||||||||||||||
| 632 | 14 | $l =~ s/^\s*\+/$PREFIX\:\:/; | |||||||||||||||||||||||||||||||
| 633 | 14 | ▶ | unless($l =~ s/^\s*\-/$last\:\:/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 634 | 6 | $last = $l; | |||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||
| 636 | 14 | ▶ | if ($l =~ s/^\s*\~//) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 637 | 2 | ▶ | $last = $PREFIX ? ($PREFIX . '::' . $l) : $l; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 638 | 2 | $l = ''; | |||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||
| 640 | 14 | $l; | |||||||||||||||||||||||||||||||
| 641 | 26 | ▶ | } @{$attrs{with}}) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 642 | : ''; | ||||||||||||||||||||||||||||||||
| 643 | 26 | ▶ | $attrs{use} = $attrs{use} ? join('', map { sprintf("\tuse %s;\n", $_) } @{$attrs{use}}) : ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 644 | 26 | $body =~ s/(^{)|(}$)//g; | |||||||||||||||||||||||||||||||
| 645 | 26 | return $body, %attrs; | |||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||
| 648 | 26 | ▶ | sub perl_tidy { | ||||||||||||||||||||||||||||||
|
Subroutine
perl_tidy: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 649 | 26 | my $source = shift; | |||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||
| 651 | 26 | my $dest_string; | |||||||||||||||||||||||||||||||
| 652 | my $stderr_string; | ||||||||||||||||||||||||||||||||
| 653 | 26 | my $errorfile_string; | |||||||||||||||||||||||||||||||
| 654 | 26 | my $argv = "-npro"; # Ignore any .perltidyrc at this site | |||||||||||||||||||||||||||||||
| 655 | 26 | $argv .= " -pbp"; # Format according to perl best practices | |||||||||||||||||||||||||||||||
| 656 | 26 | $argv .= " -nst"; # Must turn off -st in case -pbp is specified | |||||||||||||||||||||||||||||||
| 657 | 26 | $argv .= " -se"; # -se appends the errorfile to stderr | |||||||||||||||||||||||||||||||
| 658 | 26 | $argv .= " -nola"; # Disable label indent | |||||||||||||||||||||||||||||||
| 659 | 26 | $argv .= " -t"; # Use tab instead of 4 spaces | |||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||
| 661 | 26 | my $error = Perl::Tidy::perltidy( | |||||||||||||||||||||||||||||||
| 662 | argv => $argv, | ||||||||||||||||||||||||||||||||
| 663 | source => \$source, | ||||||||||||||||||||||||||||||||
| 664 | destination => \$dest_string, | ||||||||||||||||||||||||||||||||
| 665 | stderr => \$stderr_string, | ||||||||||||||||||||||||||||||||
| 666 | errorfile => \$errorfile_string, # ignored when -se flag is set | ||||||||||||||||||||||||||||||||
| 667 | ##phasers => 'stun', # uncomment to trigger an error | ||||||||||||||||||||||||||||||||
| 668 | ); | ||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||
| 670 | 26 | ▶ | if ($error) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 671 | # serious error in input parameters, no tidied output | ||||||||||||||||||||||||||||||||
| 672 | 0 | print "<<STDERR>>\n$stderr_string\n"; | |||||||||||||||||||||||||||||||
| 673 | 0 | die "Exiting because of serious errors\n"; | |||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||
| 676 | 26 | return $dest_string; | |||||||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||
| 679 | 9 | 1; | |||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||
| 681 | __END__ | ||||||||||||||||||||||||||||||||