-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild.PL
2755 lines (2334 loc) · 125 KB
/
Build.PL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!perl -w -- ## emacs -*- tab-width: 4; mode: cperl; indent-tabs-mode: nil; basic-offset: 2 -*- ## (jedit) :tabsize=4:mode=perl: ## (notepad++) vim:ts=4:sw=2:et:sta:sts=2 ## no critic ( CodeLayout::RequireTidyCode Modules::ProhibitExcessMainComplexity ) ## spell-checker: enableCompoundWords
#$Id: Build.PL,v 0.4.1.340 ( r112:594c42f8f73c [mercurial] ) 2013/12/26 05:30:45 rivy $
## no critic ( CodeLayout::ProhibitParensWithBuiltins RequireExtendedFormatting RequireLineBoundaryMatching RequireCarping )
## ToDO: expand upon assert_os to allow or disallow OS subtypes (Win9x, XP, ME, etc)
## TODO?: remove the '_' from the version for output dist files (>> will this cause a problem for PPM or CPAN with some sort of version mismatch between filename and META.yml
## TODO?: .. or just remove VERSION code generating the alpha '_' within the version? does it matter? does the '_' interfere with version comparisons on CPAN?
## ...... these don't seem to be a problem
# ToDO: open a defect ticket about error leakage for checking compiler presence in ExtUtils::CBuilder :: should be done in CBuilder with STDERR redirect
# ToDO: open a defect ticket about error leakage for checking gpg presence in Module::Signature :: should be done in Module::Signature with STDERR redirect
## # EG: #>perl -e "use File::Spec; $n = File::Spec->devnull(); if (qx{gpg --version 2>$n} =~ /GnuPG.*?\s*([0-9.]+)\s*$/m) { $h = $1 } else { $h = qq{NULL}; }; print $h"
## TODO: add an 'upload' action to use cpan_upload... to upload the basic distribution to CPAN
## : depends(testall) without errors
## ToDO: redirect STDERR to STDOUT for skipcheck (currently all output goes to STDERR)
## TODO: flesh out stub documentation for additional custom actions
## TODO: add/check compatibility for use of module PPM when installed (for non-ActiveState perl distributions)
## TODO: bring up to date with most recent META.yml spec and include all fields in DEFAULTS
# refs:
# [META.yml Specification] http://module-build.sourceforge.net/META-spec-current.html
# [Module::Install] http://search.cpan.org/~ADAMK/Module-Install (see README info)
use strict;
use warnings;
use utf8; # script source code is utf8 compatible/encoded ## note: v5.8 syntax per `perlver`
# use 5.008008; # minimum perl version ## v5.8.8 ~ required for decent basic Unicode support
use 5.006001; # v5.6.1: earliest tested version ## v5.5: for AUTHOR and ABSTRACT in Makefile.PL; v5.6: for 'our', three-argument open, indirect filehandles, extended versions for 'use' [ref: http://www.dagolden.com/index.php/369/version-numbers-should-be-boring @@ https://archive.is/7PZQL @@ http://www.webcitation.org/66Z1eHR17]
use English qw( -no_match_vars ); # enable long-form built-in variable names; '-no_match_vars' avoids regex performance penalty for perl versions <= 5.16
# use lib qw/ inc /;
# use open IN => ":crlf :encoding(utf8)", OUT => ":raw :utf8";
# use open ':std';
# VERSION: major.minor.release[.build]] { minor is ODD => alpha/beta/experimental; minor is EVEN => stable/release }
# generate VERSION from $Version: 0.1.0.198571514 $ SCS tag
# $defaultVERSION :: used to make the VERSION code resilient vs missing keyword expansion
# $generate_alphas :: 0 => generate normal versions; true/non-0 => generate alpha version strings for ODD numbered minor versions
# [NOTE: perl 'Extended Version' (multi-dot) format is preferred and created from any single dotted (major.minor) or non-dotted (major) versions; see 'perldoc version']
use version qw(); our $VERSION; { my $defaultVERSION = '0.4'; my $generate_alphas = 0; $VERSION = ( $defaultVERSION, qw( $Version: 0.4.1.340 $ ))[-2]; if ($VERSION =~ /^\d+([\._]\d+)?$/msx) {$VERSION .= '.0'; if (!defined($1)) {$VERSION .= '.0'}}; if ($generate_alphas) { $VERSION =~ /(\d+)[\._](\d+)[\._](\d+)(?:[\._])?(.*)/msx; $VERSION = $1.'.'.$2.((!$4&&($2%2))?'_':'.').$3.($4?((($2%2)?'_':'.').$4):q{}); $VERSION = version->new( $VERSION ); }; } ## no critic ( ProhibitCallsToUnexportedSubs ProhibitCaptureWithoutTest ProhibitNoisyQuotes ProhibitMixedCaseVars ProhibitMagicNumbers Capitalization RequireConstantVersion ProhibitEscapedMEtaCharacters )
use FindBin; () = eval {FindBin::again()}; # FindBin paranoia ## swallow errors for older FindBin without `FindBin::again()`
##- config
my %config;
## config options which are NOT configurable in config file ... ToDO: change to alternate name or use prefix 'ro_...' and logic on read to avoid overwrites
# config must (may?) be done via a local config file [REQUIRED ... ToDO: make OPTIONAL?] ## allows Build.PL to be maintained separately and used without changes between modules
$config{'rc_filename'} = 'Build.PL.config'; ## # configuration file name (in .NET style)
$config{'self_path'} = File::Spec->canonpath( $PROGRAM_NAME );
$config{'self_parent_path'} = File::Spec->canonpath( $FindBin::RealBin );
$config{'dist_path'} = $config{'self_parent_path'};
# Module::Build DEFAULTS [ ** DO NOT CHANGE, use the Build.PL.config to set the values ]
# * required
$config{'dist_name'} = undef;
$config{'dist_abstract'} = undef;
$config{'dist_author'} = undef;
$config{'license'} = undef;
# * optional
$config{'module_name'} = undef; # "primary" module (for construction of README, .packlist, etc); will be calculated/constructed if not defined
$config{'dist_version'} = undef; # will be constructed if not defined
#
$config{'exports_aref'} = undef; # expected symbol table exports (no obvious default; single ARRAY ref for 'default' module, or HASH of ARRAYs to specify multiple modules)
$config{'recommends_href'} = {}; # distribution recommendations (no obvious default)
$config{'requires_href'} = {}; # distribution requirements (no obvious default)
# ... additional meta info (default to Meta::Spec v2 format; see <https://metacpan.org/pod/CPAN::Meta::Spec>)
$config{'meta_add_href'} = {'meta-spec'=>{version=>'2'}}; # key/value pairs to "add" to META files (no obvious default except default to meta-spec v2); note: completely overwrites META ARRAY or HASH values
$config{'meta_merge_href'} = {'meta-spec'=>{version=>'2'}}; # key/value pairs to "merge" into META files (no obvious default except default to meta-spec v2); note: merges values into META ARRAY or HASH values
#
$config{'dynamic_config'} = 0; # Build.PL must be executed in order to determine prereqs (metadata only is not enough) [ref: <https://metacpan.org/pod/CPAN::Meta::Spec#dynamic_config>]
#
$config{'configure_requires_href'} = { # basic distribution requirements for configuration (ie, requirements needed to run `perl Build.PL`); ref: https://www.socialtext.net/perl5/configure_requires [@2011.04.15.2129@ http://www.webcitation.org/5xydysS2l ]
'perl' => '5.6.1',
'Module::Build' => '0.421', ## Module::Build v0.421+ required to avoid META.json / META.yml deletion bug during `perl Build.PL` (can be seen in StrawberryPerl v5.14.4.1 and v5.16.3.1 distrubutions)
'version' => '0.77', ## version v0.77+ needed for v5.10+ extended version support & declare->()
# Build.PL
'Cwd' => '0',
'Config' => '0',
'File::Basename' => '0',
'File::Find' => '0',
'File::Spec' => '0', 'File::Spec::Functions' => '0',
'FindBin' => '0',
# subclass code
'ExtUtils::Manifest' => '1.54', ## ExtUtils::Manifest v1.54+ only needed for clients with MANIFEST file names containing internal whitespace; added here for convenience
'File::Basename' => '0',
'File::Glob' => '0',
'File::Spec' => '0', 'File::Spec::Functions' => '0',
'File::Path' => '0',
'File::Which' => '0',
'IO::File' => '0',
'Text::Template' => '1.44', ## Text::Template v1.44+ required for minimally complete Text::Template API
'URI' => 0,
# * TAP::Harness hack/manipulation
'TAP::Harness' => '0', 'TAP::Formatter::Console' => '0', 'TAP::Formatter::Color' => '0',
};
$config{'build_requires_href'} = { # distribution requirements to build / install (eg, `build` and `build install`)
%{$config{'configure_requires_href'}},
};
$config{'test_recommends_href'} = {}; # distribution recommendations for testing (no obvious default)
$config{'test_requires_href'} = { # distribution requirements to test (eg, `build test`)
%{$config{'build_requires_href'}},
# module requirements for the usual basic tests
'Carp' => '0',
'CPAN::Meta' => '0',
'ExtUtils::Manifest' => '1.54', ## ExtUtils::Manifest v1.54+ only needed for clients with MANIFEST file names containing internal whitespace; added here for convenience
'File::Spec' => '0', 'File::Spec::Functions' => '0',
'Module::Build' => '0',
'Probe::Perl' => '0',
'Test::CPAN::Meta' => '0',
'Test::CPAN::Meta::JSON' => '0',
'Test::Differences' => '0',
'Test::More' => '0',
'version' => '0.77', ## version v0.77+ needed for v5.10+ extended version support & declare->()
};
$config{'sign'} = 'true'; # always sign the distribution, if possible (note: this is only used when the distribution is built/tested (or when testing the author signature ($ENV{TEST_ALL} or $ENV{TEST_SIGNATURE} are set)))
$config{'create_readme'} = 'true'; # create README from module pod
$config{'create_metafile_pl'} = 'small'; # pass all Makefile.PL functionality to Build.PL, but requires Module::Build (ERROR if Module::Build is missing; so, use 'configure_requires=>Module::Build') [see PerlDOC: module::build::compat]
$config{'recursive_test_files'} = undef; # scan the ./t directory recursively for *.t perl files to execute during testing (no obvious default)
$config{'no_index_href'} = { directory => [ 'inc', 't', 'xt' ] }; # private files/directories/packages/namespaces; will not be indexed and listed on CPAN
$config{'script_files_aref'} = []; # alternate script/executable file locations
$config{'pm_files_href'} = {}; # alternate PM file locations [to help with MakeMaker transitions]
$config{'pod_files_href'} = {}; # alternate POD file locations [to help with MakeMaker transitions]
$config{'xs_files_href'} = {}; # alternate XS file locations [to help with MakeMaker transitions]
$config{'PL_files_href'} = {}; # perl files to execute during processing (usually to generated .PL files from templates {see Module::Build::API documentation under "PL_files"})
$config{'PL_folders_aref'} = [ 'PL{,.#no-dist}' ]; # globs matching folders used to hold templating PL files; after config file processing, entries are added into the PL_files href for each matching PL file within the template folder(s) (target file location within the distribution is set automatically, reflected from the corresponding PL file location within the PL folder to the main distribution directory)
$config{'c_source'} = undef; # c source files to compile
$config{'config_href'} = {}; # modify Config.pm values for the build
# clean == all files which should not be distributed and are not committed to repo
# realclean == all build constructed files that are not committed to repo
# veryclean == ALL build constructed files
# ToDO: use repo functions to automatically construct the defaults; add a built_files hash
$config{'add_to_cleanup_aref'} = [ 'MANIFEST.bak', 'Makefile', 'Makefile.old', 'pm_to_blib', 'MYMETA.json', 'MYMETA.yml', 'SIGNATURE' ]; # globs matching extra files to clean up during "build clean"
$config{'add_to_realcleanup_aref'} = [ 'MANIFEST' ]; # globs matching extra files to clean up during "build realclean" (note: MANIFEST is always automatically generated from MANIFEST.SKIP)
$config{'add_to_verycleanup_aref'} = [ 'META.json', 'META.yml' ]; # globs matching extra files to clean up during "build veryclean"
$config{'assert_os_aref'} = []; # limit build to specific OS types (default = [] => any OS) [NOTE: entries are used as REGEXs for comparison VS $^O]
#
$config{'add_to_versioned_aref'} = [ 'bin/*' ]; # globs matching extra files which should have the distribution version number upon a successful build (these are added to the list of all files containing "provides" modules)
#
$config{'repo_commit_id_length_medium'} = 12; # length of 'medium' commit ID ('excellent' chance of uniqueness vs other commits within the repo; conflict chance ~(# repo commits):100,000,000,000,000)
$config{'repo_commit_id_length_short'} = 6; # length of 'short' commit ID ('good' chance of uniqueness vs other commits within the repo; conflict chance ~(# repo commits):10,000,000)
$config{'repo_commit_id_length_tiny'} = 4; # length of 'tiny' commit ID ('likely' chance of uniqueness vs other commits within the repo; conflict chance ~(# repo commits):50,000)
#
$config{'custom_code_href'} = {}; # custom code overrides from config
# $config{'custom_ENV_href'} = {}; # custom environment overrides (set before each dispatch) for state transfer to subordinate executables [default $ENV{_BUILD_dist_name} == $config{'dist_name'} [SET after Build.PL.config is read, unless set within config]]
#
$config{'dist_cpan'} = undef; # CPAN web front-end (URL; no obvious default)
$config{'dist_cpan_id'} = undef; # CPAN ID (no obvious default)
$config{'dist_issues'} = undef; # issue tracker web front-end (URL; no obvious default)
$config{'dist_metacpan'} = undef; # MetaCPAN web front-end (URL; no obvious default)
$config{'dist_metacpan_id'} = undef; # MetaCPAN ID (no obvious default)
$config{'dist_repo'} = undef; # public repository (URL; no obvious default)
$config{'dist_repo_host'} = undef; # hostname of public repository (URL; no obvious default)
$config{'dist_repo_id'} = undef; # public repository ID (URL; no obvious default)
$config{'dist_repo_path'} = undef; # path of public repository (URL; no obvious default)
$config{'dist_repo_web'} = undef; # public repository web front-end (URL; no obvious default)
$config{'dist_repo_web_host'} = undef; # hostname of public repository web front-end (URL; no obvious default)
$config{'dist_repo_web_path'} = undef; # path of public repository web front-end (URL; no obvious default)
$config{'dist_signature_id'} = undef; # cryptographic signature ID (no obvious default)
##
use Cwd qw//;
use Config;
use File::Basename qw/ dirname /;
use File::Find qw//;
use File::Spec;
use File::Spec::Functions qw/ rel2abs /;
use Module::Build;
use URI;
# Build.PL must be located in the main directory of the distribution (all described paths are relative to the main distribution directory)
# Build.PL expects to be executed with CWD == the Build.PL containing directory == the main directory of the distribution
# ToDO: relax this? allowing Build.PL to be re-located as long as 'dist_path' is recalculated in rc file?
if ( File::Spec->canonpath( $FindBin::RealBin ) ne File::Spec->canonpath( Cwd::getcwd ) ) { die 'Must execute Build.PL from the base directory' }
# # $config{} helper variables
# $config{'lib_path'} = undef; # auto-generated from $config{'dist_name'} during .config file parsing (should NOT be set in .config, since it is regenerated after each successful $config{'dist_name'} parse in the .config parsing section)
# $config{'module_path'} = undef; # auto-generated from $config{'dist_name'} during .config file parsing (should NOT be set in .config, since it is regenerated after each successful $config{'dist_name'} parse in the .config parsing section)
# pull in needed custom builder code
my %code = rivy_builder_code_subs();
() = eval $code{q/#/}; ## no critic ( ProhibitStringyEval ) ## init / prereq
() = eval $code{q/@/.'version'}; ## no critic ( ProhibitStringyEval ) ## version loading / manipulation
# () = eval $code{q/@/.'repo'}; ## no critic ( ProhibitStringyEval ) ## repo code
# $config{VERSION}
# * generated from any existing VERSION file in the main directory
$config{'VERSION_filename'} = 'VERSION';
%config = ( %config, version_from_vfile( rel2abs($config{'VERSION_filename'}, $config{'dist_path'}) ) );
if ( defined $config{'VERSION'} ) { my $v = $config{'VERSION'}; $v =~ s/^v//imsx; $config{'dist_version'} = $v; }
# include configuration options, if the file exists
# config file format:
# <var_name1> => <value>...
# ...
# <var_nameN> => <value>...
#
# where each "<var_name> => <value>" follows perl hash entry definition semantics (including embedded comments)
# ToDO: <value> can be multiline, terminated by EOF or next '<var_nameM> => ...' line
my $config_filename = rel2abs($config{'rc_filename'}, $config{'dist_path'});
#print "config => ".$config_filename;
if ( -e $config_filename )
{
my $comment_chars = q{#};
my $fh = undef;
open( $fh, '<', $config_filename ) or die qq{Can't open "$config_filename": $OS_ERROR\n};
my $line = 0;
while ( my $s = <$fh> )
{
$line++;
#eval $s;
my ( $key, $value );
if ( $s =~ m/^\s*$/msx ) { next; } # skip any blank line
if ( $s =~ m/^\s*(?:[$comment_chars]|\/\/).*$/msx ) { next; } # skip any line starting with '#', ';', q{'}, or '//' as a comment line
if ( $s =~ m/^\s*(.*?)\s*=>\s*(.*)$/msx )
{ ## quoted values are allowed with perl quoting semantics
$key = $1;
$value = $2;
if ( $key =~ m/^user_/msx || exists $config{$key} )
{ ## eval $value into $config{}
my $ev = q/$/.'config'."{$key} = $value";
my $e = 0; my $w = 0;
$SIG{'__WARN__'} = sub { if (!$w) {chomp($w = $_[0]);} };
$e = !eval "$ev; 1"; ## no critic ( ProhibitStringyEval )
# print STDERR "w = $w\n";
$SIG{'__WARN__'} = 'DEFAULT'; ## NOTE: 'IGNORE' is not supported by $SIG{'__WARN__'} [refs: [perlvar - %SIG] http://perldoc.perl.org/perlvar.html#%SIG , [Perl's Warn and Die Signals] http://www.perlmonks.org/?node_id=51097 , http://www.perlmonks.org/?node_id=673637 ]
if ($w || $e) {warn qq{build: warning, malformed configuration entry: "$config_filename", line $line\n};}
if ($key eq 'dist_name' && (not defined $config{'module_name'})) {
# guess module_name
$config{'module_name'} = $config{'dist_name'}; $config{'module_name'} =~ s/-/::/gmsx;
}
# if ($key eq 'dist_name') {
# # if ($key eq 'module_name') {
# # $config{'lib_path'} = 'lib/' . join( q{/}, split( /::/msx, ( $config{'module_name'} =~ m/(.*)::.*?$/msx ? $1 : q{} ) ) ); # relative path to the module's lib location (using standard Module::Builder rules)
# # $config{'module_path'} = $config{lib_path} . q{/} . (split(q{::},$config{module_name}))[-1] . '.pm'; # relative path to the usual location of a module's package file (using 'lib_path')
# # early construction of dist_version_from from dist_name, if not already defined
# if ( ! $config{dist_version_from} ) { $config{dist_version_from} = 'lib/' . join( q{/}, split(/-/msx, $config{'dist_name'}) ) . '.pm'; }
# }
if ($key eq 'dist_repo') {
my $url = URI->new( $config{'dist_repo'} );
$config{'dist_repo_host'} = $url->authority if not defined $config{'dist_repo_host'};
$config{'dist_repo_path'} = $url->path if not defined $config{'dist_repo_path'};
}
if ($key eq 'dist_repo_web') {
my $url = URI->new( $config{'dist_repo_web'} );
$config{'dist_repo_web_host'} = $url->authority if not defined $config{'dist_repo_web_host'};
$config{'dist_repo_web_path'} = $url->path if not defined $config{'dist_repo_web_path'};
}
if ($key eq 'module_name' && (not defined $config{'dist_name'})) {
# guess dist_name
$config{'dist_name'} = $config{'module_name'}; $config{'dist_name'} =~ s/::/-/gmsx;
}
if ($key eq 'VERSION_filename') {
# determine VERSION from file, if present
%config = ( %config, version_from_vfile( rel2abs($config{'VERSION_filename'}, $config{'dist_path'}) ) );
if ( defined $config{'VERSION'} ) { my $v = $config{'VERSION'}; $v =~ s/^v//i; $config{'dist_version'} = $v; }
}
}
else { die qq{Unknown configuration key '$key' @ ("$config_filename", line $line)\n}; }
}
else { die qq{Malformed configuration line @ ($config_filename, line $line)\n}; }
}
close $fh or die qq{Can't close "$config_filename" after reading: $OS_ERROR\n};
}
# print STDERR '$config{VERSION} = '.($config{VERSION} ? $config{VERSION} : q{})."\n";
# print STDERR '$config{VERSION} = '.($config{VERSION} ? $config{VERSION} : q{})."\n";
# SETUP PL_files from PL_folders, if needed
if ( @{$config{'PL_folders_aref'}} > 0 )
{
my $OS_no_case = File::Spec->case_tolerant();
my @PL_globs = @{$config{'PL_folders_aref'}};
my @PL_folders = map { glob } @PL_globs;
my %files;
foreach my $folder ( @PL_folders ) {
if ( -e $folder ) {
my $match_re = ($OS_no_case ? '(?i)' : q{}) . '[.](?i:pl)$';
my $subst_re = ($OS_no_case ? '(?i)' : q{}) . "^$folder\/(.*)[.](?i:pl)\$";
File::Find::find( sub { my $f_s = $File::Find::name; my $f_d = $f_s; /$match_re/ && ( $f_d =~ s/$subst_re/$1/ ) && ( $files{$f_s} = $f_d ) }, $folder );
}
}
$config{'PL_files_href'} = { %{$config{'PL_files_href'}}, %files };
##my @files = %files;
##print "PL files in PL_folders = [ @files ]\n";
}
# SETUP PL_target_files
my %PL_target_files;
while (my (undef, $to) = each %{$config{'PL_files_href'}}) {
$PL_target_files{$to} = 1;
}
$config{'PL_target_files_href'} = { %PL_target_files };
# SETUP versioned_files
# if ( @{$config{'add_to_versioned_aref'}} <= 0 ) { $config{'add_to_versioned_aref'} = [ $config{module_path}, qw( bin/* ) ] };
##if ( @{$config{'versioned_file_globs_exclude_aref'}} <= 0 ) { $config{'versioned_file_globs_exclude_aref'} = [ qw( bin/*.pl.pl ) ] };
## ToDO: add PL_file targets ... or take from META / provides {module => file / version}
# if ( @{$config{'add_to_versioned_aref'}} <= 0 ) { $config{'add_to_versioned_aref'} = [ $config{module_path}, values %{$config{'PL_files_href'}} ] };
# if ( @{$config{'add_to_versioned_aref'}} <= 0 ) { $config{'add_to_versioned_aref'} = [ $config{dist_version_from}, qw( bin/* ) ] };
$config{'add_to_versioned_aref'} = [ @{$config{'add_to_versioned_aref'}}, ( grep { defined && /[.](?:bat|cmd|pl|pm)$/imsx } keys %{$config{'PL_target_files_href'}} ) ];
#use Data::Dumper;
#print Dumper( %config );
#print Dumper( $config{'dist_name'} );
#print Dumper( $config{'os_req'} );
##
##
# UPDATE files for 'clean'
# * if using MSVC compiler ('cl'), add Visual C debug files ('vc[1-9][0-9]*.pdb') to cleanup
if (lc($Config{'cc'}) eq 'cl') { $config{'add_to_cleanup_aref'} = [ @{$config{'add_to_cleanup_aref'}}, 'vc[1-9][0-9]*.pdb', ]; }
# * automatically add distribution files to cleanup
$config{'add_to_cleanup_aref'} = [ @{$config{'add_to_cleanup_aref'}} , ( map { $config{'dist_name'}.q/-/.$config{'VERSION'}.$_ } ( '-PPM.tar.gz', '.tar.gz', '-*.par' ) ) , $config{'dist_name'}.'.ppd', ];
# UPDATE files for 'realclean'
# * automatically add Makefile.PL to cleanup if $config{'create_metafile_pl'} == ANY
if ($config{'create_metafile_pl'}) { $config{'add_to_realcleanup_aref'} = [ 'Makefile.PL', @{$config{'add_to_realcleanup_aref'}} ]; }
# * automatically add README to cleanup if $config{'create_readme'} == 'true'
if ($config{'create_readme'}) { $config{'add_to_realcleanup_aref'} = [ 'README', @{$config{'add_to_realcleanup_aref'}} ]; }
# UPDATE files for 'veryclean'
# * automatically add PL_target_files
$config{'add_to_verycleanup_aref'} = [ sort keys %{$config{'PL_target_files_href'}}, @{$config{'add_to_verycleanup_aref'}} ];
##
if ( ! $config{'dist_name'} && ! $config{'module_name'} ) { die 'Either $config{dist_name} or $config{module_name} must be defined' . "\n"; } ## no critic ( RequireCarping RequireInterpolation )
if ( ! $config{'dist_abstract'} ) { die '$config{dist_abstract} must be defined' . "\n"; } ## no critic ( RequireCarping RequireInterpolation )
if ( ! $config{'dist_author'} ) { die '$config{dist_author} must be defined' . "\n"; } ## no critic ( RequireCarping RequireInterpolation )
if ( ! $config{'license'} ) { die '$config{license} must be defined' . "\n"; } ## no critic ( RequireCarping RequireInterpolation )
if ( defined $config{'VERSION'} ) { my $v = $config{'VERSION'}; $v =~ s/^v//imsx; $config{'dist_version'} = $v; }
#assert( $config{'lib_path'} ) # should be defined if $config{'dist_name'} has been parsed (as asserted above)
# if ( !$config{'custom_ENV_href'}->{'_BUILD_dist_name'} ) { $config{'custom_ENV_href'}->{'_BUILD_dist_name'} = $config{'dist_name'}; }
##if ( !$config{'custom_ENV_href'}->{'_BUILD_versioned_file_globs'} ) { $config{'custom_ENV_href'}->{'_BUILD_versioned_file_globs'} = join(q{;}, ( $config{module_path}, qw( bin/*.pl bin/*.bat ) )); } ## versioned files default to main file and all files in the bin directory
## ToDO: # CHANGE: '_BUILD_versioned_file_globs' => [ map {recursive_glob} qw{lib/*.pm bin/*.bat bin/*.pl} ]
#use lib 'inc';
#require Devel::AssertOS; import Devel::AssertOS ( @{$config{'assert_os_aref'}} );
# [DONE: WORKS fine] TODO: check with CPAN testers whether the current failure output string is close enough to the 'standard' "OS unsupported\n" string so that test failures are NA for unsupported OS's
if (defined($config{'assert_os_aref'}) && @{$config{'assert_os_aref'}}) { my $found = 0; for my $os (@{$config{'assert_os_aref'}}) { $found = 1 if $^O =~ /$os/; }; if (!$found) { die "OS unsupported : $config{module_name} is designed to be used for ( @{$config{assert_os_aref}} ) systems only - installation aborted\n";}; }; ## no critic (Variables::ProhibitPunctuationVars ErrorHandling::RequireCarping)
my $class = Module::Build->subclass( class => 'RIVY::Builder', code => rivy_builder_code() );
# test_recommends is not directly supported => use meta_merge
if ( keys %{$config{'test_requires_href'}} ) { $config{'meta_merge_href'} = { %{$config{'meta_merge_href'}}, prereqs => { test => { recommends => $config{'test_recommends_href'} } } }; }
my %optional_args = (); # Module::Build::new() optional args (only included if they are non-empty; otherwise, if included as empty list(s)/hash(es) in new(), Module::Build carps that the specified [and needed] files are missing)
if ( keys %{$config{'meta_add_href'}} ) { %optional_args = ( %optional_args, meta_add => { %{$config{'meta_add_href'}} }); }
if ( keys %{$config{'meta_merge_href'}} ) { %optional_args = ( %optional_args, meta_merge => { %{$config{'meta_merge_href'}} }); }
if ( keys %{$config{'configure_requires_href'}} ) { %optional_args = ( %optional_args, configure_requires => { %{$config{'configure_requires_href'}} }); }
if ( keys %{$config{'test_requires_href'}} ) { %optional_args = ( %optional_args, test_requires => { %{$config{'test_requires_href'}} }); }
if ( keys %{$config{'no_index_href'}} ) { %optional_args = ( %optional_args, no_index => { %{$config{'no_index_href'}} }); }
if ( @{$config{'script_files_aref'}} ) { %optional_args = ( %optional_args, script_files => [ @{$config{'script_files_aref'}} ]); }
if ( keys %{$config{'pm_files_href'}} ) { %optional_args = ( %optional_args, pm_files => { %{$config{'pm_files_href'}} }); }
if ( keys %{$config{'pod_files_href'}} ) { %optional_args = ( %optional_args, pod_files => { %{$config{'pod_files_href'}} }); }
if ( keys %{$config{'xs_files_href'}} ) { %optional_args = ( %optional_args, xs_files => { %{$config{'xs_files_href'}} }); }
my $build = $class->new(
get_options => { color => { type => '=s' } }, ## option to output in color ## OPTION color => 0/never/no/off; 1/on/yes; always # parsed in dispatch()
module_name => $config{'module_name'},
dist_name => $config{'dist_name'},
dist_version_from => $config{'dist_version_from'},
dist_abstract => $config{'dist_abstract'},
dist_author => $config{'dist_author'},
license => $config{'license'},
dist_version => $config{'dist_version'},
requires => { %{$config{'requires_href'}} },
recommends => { %{$config{'recommends_href'}} },
dynamic_config => $config{'dynamic_config'},
build_requires => { %{$config{'build_requires_href'}} },
sign => $config{'sign'},
recursive_test_files => $config{'recursive_test_files'},
create_readme => $config{'create_readme'},
create_metafile_pl => $config{'create_metafile_pl'},
%optional_args, ## meta_add, meta_merge, configure_requires, test_requires, no_index, script_files, pm_files, pod_files, xs_files
config => { %{$config{'config_href'}} },
PL_files => { %{$config{'PL_files_href'}} },
add_to_cleanup => [ @{$config{'add_to_cleanup_aref'}} ],
add_to_realcleanup => [ @{$config{'add_to_realcleanup_aref'}} ],
add_to_verycleanup => [ @{$config{'add_to_verycleanup_aref'}} ],
);
# push $config{*} info into $build->notes
foreach ( keys %config ) {
$build->notes("config/$_" => $config{$_});
# print STDERR "$_ ... $config{$_}\n" ;
##print "$_ => ".$build->notes("config/$_")."\n";
}
$build->create_build_script;
####
sub version_from_vfile { ## ( $:file ) => %:version_info
# determine VERSION from file, if present
# VERSION: Major.minor[_alpha] { if no alpha: minor is ODD => alpha (aka, developer, beta, or experimental), minor is EVEN => stable or release }
# * NOTE: "boring" versions are preferred (ref: http://www.dagolden.com/index.php/369/version-numbers-should-be-boring @@ https://archive.is/7PZQL @@ http://www.webcitation.org/66Z1eHR17])
my $VERSION_filename = shift;
my %RETval = ();
$RETval{'VERSION'} = undef;
if ( -e $VERSION_filename ) {
my $fh;
open( $fh, '<', $VERSION_filename ) or die qq{Can't open "$VERSION_filename": $OS_ERROR\n}; ## no critic ( RequireCarping )
my $file_contents;
{# slurp entire file
local $/ = undef;
$file_contents = <$fh>;
}
close $fh or die qq{Can't close "$VERSION_filename" after reading: $OS_ERROR\n}; ## no critic ( RequireCarping )
$file_contents = q// if not defined $file_contents;
# remove and save any leading whitespace and/or trailing non-version text (comments, etc)
if ( $file_contents =~ /^([\s\n]*)((?:\d|[._])+)((?:.|\s)*?)$/msx ) {
$RETval{'VERSION_prefix'} = $1;
$RETval{'VERSION'} = $2;
$RETval{'VERSION_suffix'} = $3;
$RETval{'VERSION'} =~ s/(.*?)[._]*$/$1/; # remove any trailing '.|_'
# print qq{Found version ('$RETval{VERSION}') in "$VERSION_filename"\n};
}
else
{
$RETval{'VERSION'} = '0.001';
warn qq{build: warning, using default version ('$RETval{VERSION}'); no version found in "$VERSION_filename"\n};
}
( $RETval{'VERSION_M'}, $RETval{'VERSION_m'}, $RETval{'VERSION_a'} ) = ( $RETval{'VERSION'} =~ /\d+/gmsx );
$RETval{'VERSION'} = version_f( $RETval{'VERSION_M'}, $RETval{'VERSION_m'}, $RETval{'VERSION_a'} );
# print "\\$VERSION = '$RETval{VERSION}'\n";
}
##print STDERR '\\$RETval{VERSION} = '.($RETval{VERSION} ? $RETval{VERSION} : q{})."\n";
return %RETval;
}
####
sub _is_const { return !eval { ($_[0]) = $_[0]; 1; }; }
sub _encodeQQ
{
my $arg_ref;
$arg_ref = \@_;
$arg_ref = [ @_ ] if defined wantarray; ## no critic (ProhibitPostfixControls) ## break aliasing if non-void return context
for my $arg ( @{$arg_ref} ) {
if (_is_const($arg)) { Carp::carp 'Attempt to modify readonly scalar'; return; }
$arg =~ s/([^[:word:].,;:])/'\x{'.sprintf("%x", ord($1)).'}'/esg;
}
return wantarray ? @{$arg_ref} : "@{$arg_ref}";
}
sub _encodeQ
{
my $arg_ref;
$arg_ref = \@_;
$arg_ref = [ @_ ] if defined wantarray; ## no critic (ProhibitPostfixControls) ## break aliasing if non-void return context
for my $arg ( @{$arg_ref} ) {
if (_is_const($arg)) { Carp::carp 'Attempt to modify readonly scalar'; return; }
$arg =~ s/([\\{}])/\\$1/sg;
}
return wantarray ? @{$arg_ref} : "@{$arg_ref}";
}
####
sub rivy_builder_code
{
my $code = q{};
my %code = rivy_builder_code_subs();
for (keys %{$config{custom_code_href}}) { $code{$_} = $config{custom_code_href}->{$_}; }
for (sort keys %code) { $code .= $code{$_}; }
return $code;
}
sub rivy_builder_code_subs
{; ## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars ValuesAndExpressions::ProhibitImplicitNewlines)
my %code;
$code{q/#/} = q{
use strict;
use warnings;
use English qw( -no_match_vars ); ## enable long-form built-in variable names; '-no_match_vars' avoids regex performance penalty for perl versions <= 5.16
# use open IN => ":crlf :encoding(UTF-8)", OUT => ":raw :utf8";
# use open ':std';
use File::Basename;
use File::Glob qw//;
use File::Spec qw//;
use File::Spec;
use File::Spec::Functions;
use File::Path;
use File::Which;
use IO::File;
use Text::Template;
use URI;
# print STDERR "\#(use section): HERE\\n";
};
$code{'@qprintf'} = q{
{
my @encoding;
my @printf_encoding;
for (my $n = 0; $n <= 0xff; $n++) {
$encoding[$n] = sprintf "\\%02x", $n;
$printf_encoding[$n] = $encoding[$n];
}
for (my $n = 0; $n <= 0x7f; $n++) {
my $c = chr($n);
next if $c =~ /[%"'\\*\\?\\[\\]\\{\\}[:^graph:]]/; # escape character, quotes, printf format specifier, special glob characters
$printf_encoding[$n] = $c;
}
sub qprintf ## ( @:strings ) => @:printf encoded strings
{
my @in = @_;
# encode input as equivalent printf compatible strings (also, portable)
my $IFS = $ENV{IFS};
if ( not defined $IFS || $IFS eq q// ) { $IFS = " \n\t" }
## replace IFS characters in @printf_encoding with encoded equivalents
foreach ( split q//, $IFS ) { $printf_encoding[ord($_)] = $encoding[ord($_)] }
## foreach @_ { replace each character with its equivalent encoding }
foreach ( @in ) { $_ =~ s/(.)/$printf_encoding[ord($_)]/egmsx }
return @in;
}
}
};
$code{'@version'} = q{
# ref: http://www.dagolden.com/index.php/369/version-numbers-should-be-boring @@ https://archive.is/7PZQL @@ http://www.webcitation.org/66Z1eHR17]
# NOTE: VERSION == Major.minor[_alpha] { if no alpha: minor is ODD => alpha (aka, developer, beta, or experimental), minor is EVEN => stable or release }
sub version_f { ## ( $:major, $:minor, $:alpha ) => $:formatted version string ("boring" style)
my ( $major, $minor, $alpha ) = @_;
$major = '1' if not defined $major;
$minor = '0' if not defined $minor || $minor eq q//;
$alpha = q// if not defined $alpha;
if (( $minor % 2 ) && ($alpha eq q//) ) { $alpha = 1; }
my $v;
$v = sprintf( '%d', $major );
$v .= sprintf( q/./.((($major == 0) && ($alpha eq q//)) ? '%d' : '%03d'), $minor );
$v .= sprintf( q/_/.(($alpha == 1) ? '%d' : '%03d'), $alpha ) if $alpha ne q//;
return $v;
}
};
$code{'repo'} = q{
sub repo_property_update ## ( )
{
my $self = shift;
# print STDERR "repo_property_update()\\n";
use File::Spec::Functions qw( rel2abs );
use File::Basename qw( dirname );
my $filename;
my $null = File::Spec->devnull();
my $repo_commands_ref = undef;
if ( not $repo_commands_ref ) {
# prefer GIT
# : GIT
$filename = rel2abs('.git', $self->base_dir);
if ( -d $filename )
{
# if ( system("git --version 1>$null 2>&1") == 0 ) { return 'git' };
if ( system("git --no-pager log -1 --pretty=oneline 1>$null 2>&1") == 0 ) { $repo_commands_ref = _repo_commands('git'); };
}
}
if ( not $repo_commands_ref ) {
# : Mercurial
$filename = rel2abs('.hg', $self->base_dir);
if ( -d $filename )
{
if ( system("hg --version 2>&1 1>$null") == 0 ) { $repo_commands_ref =_repo_commands('hg'); };
}
}
if ( $repo_commands_ref ) {
foreach ( keys %{$repo_commands_ref} ) {
# print STDERR "\\$repo_commands_ref->{$_}()=".scalar($repo_commands_ref->{$_}())."\n";
$self->notes( "repo_$_" => scalar( $repo_commands_ref->{$_}() ) );
}
}
return;
}
sub _repo_commands # ( [ $:repo_type ] ) => $REPO_FUNCTION_REF
{
my $repo_type = shift; # [ 'git', 'hg' ]
my $repo_function_ref;
my $function_name;
# ref: [Mercurial for GIT users] http://mercurial.selenic.com/wiki/GitConcepts @@ http://archive.is/pnLtQ @@ http://webcitation.org/6MAMUgtwV
# branch
$function_name = 'branch';
$repo_function_ref->{git}{$function_name} = sub {
my @lines = qx{git rev-parse --abbrev-ref HEAD};
my $RETval = $lines[0];
chomp( $RETval ) if defined $RETval;
return $RETval;
};
$repo_function_ref->{hg}{$function_name} = sub {
my @lines = qx{hg branch};
my $RETval = $lines[0];
chomp( $RETval ) if defined $RETval;
return $RETval;
};
# commit_author
$function_name = 'commit_author';
$repo_function_ref->{git}{$function_name} = sub {
my @lines = qx{git show --pretty="%aN <%aE>"};
my $RETval = $lines[0];
chomp( $RETval ) if defined $RETval;
return $RETval;
};
$repo_function_ref->{hg}{$function_name} = sub {
my @lines = qx{hg log -r . --template "{author}"};
my $RETval = $lines[0];
chomp( $RETval ) if defined $RETval;
return $RETval;
};
# commit_number
$function_name = 'commit_number';
$repo_function_ref->{git}{$function_name} = sub {
my @lines = qx{git rev-list HEAD};
return scalar(@lines);
};
$repo_function_ref->{hg}{$function_name} = sub {
my @lines = qx{hg log -r . --template "{rev}"};
my $RETval = $lines[0];
chomp( $RETval ) if defined $RETval;
return $RETval;
};
# commit_id
$function_name = 'commit_id';
$repo_function_ref->{git}{$function_name} = sub {
# ref: [How to retrieve the hash for the current commit in Git?] http://stackoverflow.com/a/949391/43774
my @lines = qx{git rev-parse HEAD};
my $RETval = $lines[0];
chomp( $RETval ) if defined $RETval;
return $RETval;
};
$repo_function_ref->{hg}{$function_name} = sub {
my @lines = qx{hg log -r . --template "{node}"};
my $RETval = $lines[0];
chomp( $RETval ) if defined $RETval;
return $RETval;
};
# # commit_id_of_size
# $function_name = 'commit_id_of_size';
# $repo_function_ref->{git}{$function_name} = sub {
# # ref: [How to retrieve the hash for the current commit in Git?] http://stackoverflow.com/a/949391/43774
# my $size = shift;
# my @lines = qx{git rev-parse --short=$size HEAD};
# my $RETval = $lines[0];
# chomp( $RETval ) if defined $RETval;
# return $RETval;
# };
# $repo_function_ref->{hg}{$function_name} = sub {
# my $size = shift;
# my @lines = qx{hg log -r . --template "{node}"};
# my $RETval = $lines[0];
# chomp( $RETval ) if defined $RETval;
# return substr ( $RETval, 0, $size );
# };
# commit_describe
$function_name = 'commit_describe';
$repo_function_ref->{git}{$function_name} = sub {
my @lines = qx{git describe --tags --always};
my $RETval = $lines[0];
chomp( $RETval ) if defined $RETval;
return $RETval;
};
$repo_function_ref->{hg}{$function_name} = sub {
my @lines = qx{hg log -r . --template "{latesttag}-{latesttagdistance}-{node|short}\n"};
my $RETval = $lines[0];
chomp( $RETval ) if defined $RETval;
return $RETval;
};
# contributors
$function_name = 'contributors';
$repo_function_ref->{git}{$function_name} = sub {
my @lines = ();
@lines = qx{git log --format="%aN <%aE>"};
return wantarray ? @lines : \\@lines;
};
$repo_function_ref->{hg}{$function_name} = sub {
my @lines = qx{hg log --template "{author}\n"};
return wantarray ? @lines : \\@lines;
};
# files
$function_name = 'files';
$repo_function_ref->{git}{$function_name} = sub {
my @lines = split /\0/, qx{git ls-tree --full-name --full-tree --name-only -r -t -z HEAD};
return wantarray ? @lines : \\@lines;
};
$repo_function_ref->{hg}{$function_name} = sub {
my @lines = map { s/^.\s//msx; $_ } grep { /^[MARC!]\s/msx } ( split /\0/, qx{hg status --all --print0} );
return wantarray ? @lines : \\@lines;
};
# files_binary
$function_name = 'files_binary';
$repo_function_ref->{git}{$function_name} = sub {
my @lines = grep { /^-/msx } split /\0/, qx{git diff-tree -z --numstat 4b825dc642cb6eb9a060e54bf8d69288fbee4904 HEAD};
foreach ( @lines ) { s/^-\t-\t// };
return wantarray ? @lines : \\@lines;
};
$repo_function_ref->{hg}{$function_name} = sub {
my @lines = map { s/^.\s//msx; $_ } grep { /^[MARC!]\s/msx } ( split /\0/, qx{hg status --all "set:binary()" --print0} );
return wantarray ? @lines : \\@lines;
};
# files_ignored
$function_name = 'files_ignored';
$repo_function_ref->{git}{$function_name} = sub {
my @lines = map { s/^[!][!]\s//msx; $_ } grep { /^[!][!]\s/msx } ( split /\0/, qx{git status --ignored --porcelain -z} );
return wantarray ? @lines : \\@lines;
};
$repo_function_ref->{hg}{$function_name} = sub {
my @lines = map { s/^.\s//msx; $_ } grep { /^[I]\s/msx } ( split /\0/, qx{hg status --all --print0} );
return wantarray ? @lines : \\@lines;
};
# files_untracked
$function_name = 'files_untracked';
$repo_function_ref->{git}{$function_name} = sub {
my @lines = map { s/^[?][?]\s//msx; $_ } grep { /^[?][?]\s/msx } ( split /\0/, qx{git status --porcelain -z} );
return wantarray ? @lines : \\@lines;
};
$repo_function_ref->{hg}{$function_name} = sub {
my @lines = map { s/^.\s//msx; $_ } grep { /^[?]\s/msx } ( split /\0/, qx{hg status --all --print0} );
return wantarray ? @lines : \\@lines;
};
# is_dirty
$function_name = 'is_dirty';
$repo_function_ref->{git}{$function_name} = sub {
# ref: http://stackoverflow.com/questions/2657935/checking-for-a-dirty-index-or-untracked-files-with-git
my @lines = qx{git diff --shortstat};
return scalar(@lines) != 0;
};
$repo_function_ref->{hg}{$function_name} = sub {
my @lines = qx{hg status -mard};
return scalar(@lines) != 0;
};
# type
$function_name = 'type';
$repo_function_ref->{git}{$function_name} = sub {
return 'git';
};
$repo_function_ref->{hg}{$function_name} = sub {
return 'hg';
};
if ( $repo_type )
{
return $repo_function_ref->{$repo_type};
}
return $repo_function_ref;
}
};
####
$code{'#pod'} = q{
=head1 OPTIONS (CUSTOM)
Additional custom options.
=over 4
=item --color=0|no|never|off|1|on|yes|always
Force TAP::Harness color output via manipulation of TAP::Formatter (and the use of Win32::Console::ANSI for MSWin32). When color
is enabled (and Win32::Console::ANSI for MSWin32 systems) is installed, colored output is displayed reliably to the shell.
For MSWin32 systems, both CMD and TCC shells display colored output. Additionally, although the TAP::Formatter will
usually not pipe colored output, when 'always' is used, output color is enabled and piped correctly.
output as well. Normally, the TAP::Formatter will not pipe colored output.
--color=0|no|never|off disable color output
--color=1|on|yes enable color output (piped output is not colored)
--color=always enable color output (including piped output)
=back
=head1 ACTIONS (CUSTOM)
Additional custom actions.
=over 4
=item distall
Build all distributions.
=item distppm
Build the PPM distribution.
=item distpar
Build the PAR distribution.
=item PL_files
Build all files from PL templating scripts.
=item sign
Sign the current module content in the base directory (for local testing).
=item show_vfiles
Print all versioned files within module.
=item show_versions
Print all versioned files within module with their $VERSION.
=item show_PL_targets
Print all PL script target files within module.
=item smoke
Build and "smoke test" the distribution (an alias of smoke_build).
=item smoke_build
Build and "smoke test" the distribution, using Build.PL for the target distribution build.
=item smoke_make
Build and "smoke test" the distribution, using Makefile.PL and make for the target distribution build.
=item taint_test
[version 0.01]
Run regression tests (via test) with taint-mode ON. See C<test> for more information and argument specification(s).
=item taint_testall
[version 0.01]
Run all regression tests (via testall) with taint-mode ON. See C<testall> for more information and argument specification(s).
=item TRIALaction
Execute a trial action (for testing purposes).
=back
=cut
};
# $code{'@new'} = q{
# sub new{
# #my $self = shift()->_construct(@_);
# #
# #$self->{invoked_action} = $self->{action} ||= 'Build_PL';
# #$self->cull_args(@ARGV);
# #
# #die "Too early to specify a build action '$self->{action}'. Do 'perl Build.PL' instead.\n"
# #if $self->{action} && $self->{action} ne 'Build_PL';
# #
# #$self->check_manifest;
# #$self->check_prereq;
# #$self->check_autofeatures;
# #
# #$self->dist_name;
# #$self->dist_version;
# #
# #$self->_set_install_paths;
# #$self->_find_nested_builds;
# #
# #return $self;
# my $self = shift;
# my ($args, $action) = $self->read_args(@ARGV);
#
# if ($action) {
# ## $self->do_system($self->{properties}{perl}.' Build.PL'); ## causes intermittent errors as $self is not well-formed yet
# system "$^X $0";
# if ( -f 'Build' ) {
# print "Executing: perl Build @ARGV\n";
# #exit( $self->run_perl_script('Build', [], @ARGV) );
# #exit( do 'Build' );
# exit( $self->do_system("$^X Build @ARGV") );
# }
# else {
# die "Too early to specify a build action '$action'. Do 'perl Build.PL' instead.\n";
# }
# }
#
# return $self->SUPER::new( @_ );
# }
# };
$code{'ACTION_PL_files'} = q{
#[ADD] PL_files - create all templated PL files
sub ACTION_PL_files {
my $self = shift;
if ( $self->PL_files )
{
##my @entries = %{$self->PL_files};
##print "entries = [ @entries ]\n";
$self->process_PL_files;
#_or_?#$self->depends_on('code');
};
}
sub process_PL_files {
my ($self) = @_;
my $files = $self->find_PL_files;
foreach my $file (sort keys %$files) {
my $to = $files->{$file};
unless ($self->FILES_up_to_date( $to, [ $file, 'Build', 'Build.PL', 'Build.PL.config' ], { ignore_case => 1 } )) {
$self->run_perl_script($file, [], [@$to]) or die "$file failed";
# $self->add_to_cleanup(@$to);
}
}
}
sub create_note_versioned_filenames {
my $self = shift;
$self->depends_on('PL_files');
my @globs;
my @files;
my @files_to_exclude;
@globs = @{$self->notes('config/add_to_versioned_aref')};
@files = map { glob $_ } @globs;
##
####@globs = @{$self->notes('config/versioned_file_globs_exclude_aref')};
####@files_to_exclude = map { File::Glob::bsd_glob($_,File::Glob::GLOB_NOCASE()) } @globs;
####
##### ref: [How can I delete items from an array in another array in perl?] http://stackoverflow.com/a/6714829
####my %elements;
####@elements{ @files_to_exclude } = ();
####my @final_files = grep ! exists $elements{$_}, @files;
##
####$self->notes('config/add_to_versioned_aref' => [ @final_files ]);
$self->notes('config/versioned_filenames_aref' => [ @files ]);
#print "s->n(vfa) = @{$self->notes('config/versioned_files_aref')}\n";
}
};
$code{'get_template_vars'} = q{
sub get_template_vars {
# get_template_vars( [$output_filename] ) ): %vars
my $self = shift;
my $output_filename = shift;
my %vars = ();
my %notes = $self->notes;
# add notes() to template vars
for ( keys %notes ) {