1#################################################################################################################################### 2# Build Constants and Functions 3#################################################################################################################################### 4package pgBackRestBuild::Build::Common; 5 6use strict; 7use warnings FATAL => qw(all); 8use Carp qw(confess); 9use English '-no_match_vars'; 10 11use Cwd qw(abs_path); 12use Exporter qw(import); 13 our @EXPORT = qw(); 14use Storable qw(dclone); 15 16use pgBackRestDoc::Common::Log; 17use pgBackRestDoc::Common::String; 18 19#################################################################################################################################### 20# Constants 21#################################################################################################################################### 22use constant BLD_PATH => 'path'; 23 push @EXPORT, qw(BLD_PATH); 24use constant BLD_FILE => 'file'; 25 push @EXPORT, qw(BLD_FILE); 26 27use constant BLD_C => 'c'; 28 push @EXPORT, qw(BLD_C); 29use constant BLD_EXT => 'ext'; 30 push @EXPORT, qw(BLD_EXT); 31use constant BLD_HEADER => 'h'; 32 push @EXPORT, qw(BLD_HEADER); 33 34use constant BLD_CONSTANT => 'constant'; 35 push @EXPORT, qw(BLD_CONSTANT); 36use constant BLD_CONSTANT_GROUP => 'constantGroup'; 37 push @EXPORT, qw(BLD_CONSTANT_GROUP); 38use constant BLD_CONSTANT_VALUE => 'constantValue'; 39 push @EXPORT, qw(BLD_CONSTANT_VALUE); 40 41use constant BLD_DATA => 'data'; 42 push @EXPORT, qw(BLD_DATA); 43use constant BLD_DECLARE => 'declare'; 44 push @EXPORT, qw(BLD_DECLARE); 45use constant BLD_ENUM => 'enum'; 46 push @EXPORT, qw(BLD_ENUM); 47use constant BLD_LIST => 'list'; 48 push @EXPORT, qw(BLD_LIST); 49use constant BLD_NAME => 'name'; 50 push @EXPORT, qw(BLD_NAME); 51use constant BLD_PATH => 'path'; 52 push @EXPORT, qw(BLD_PATH); 53use constant BLD_SOURCE => 'buildSource'; 54 push @EXPORT, qw(BLD_SOURCE); 55use constant BLD_SUMMARY => 'summary'; 56 push @EXPORT, qw(BLD_SUMMARY); 57use constant BLD_VALUE => 'value'; 58 push @EXPORT, qw(BLD_VALUE); 59 60#################################################################################################################################### 61# bldAutoWarning - warning not to modify automatically generated files directly 62#################################################################################################################################### 63sub bldAutoWarning 64{ 65 my $strGenerator = shift; 66 67 return "Automatically generated by ${strGenerator} -- do not modify directly."; 68} 69 70push @EXPORT, qw(bldAutoWarning); 71 72#################################################################################################################################### 73# bldBanner - build general banner 74#################################################################################################################################### 75sub bldBanner 76{ 77 my $strContent = shift; 78 my $strGenerator = shift; 79 80 my $strBanner = 81 qw{/} . (qw{*} x 131) . "\n" . 82 trim($strContent) . "\n"; 83 84 if (defined($strGenerator)) 85 { 86 $strBanner .= 87 "\n" . 88 bldAutoWarning($strGenerator) . "\n"; 89 } 90 91 $strBanner .= 92 (qw{*} x 131) . qw{/} . "\n"; 93 94 return $strBanner; 95} 96 97push @EXPORT, qw(bldBanner); 98 99#################################################################################################################################### 100# Generate an enum name from a prefix and - separated name 101#################################################################################################################################### 102sub bldEnum 103{ 104 my $strPrefix = shift; 105 my $strName = shift; 106 my $bInitCapFirst = shift; 107 108 $bInitCapFirst = defined($bInitCapFirst) ? $bInitCapFirst : true; 109 my $bFirst = true; 110 111 my @stryName = split('\-', $strName); 112 $strName = undef; 113 114 foreach my $strPart (@stryName) 115 { 116 $strName .= ($bFirst && $bInitCapFirst) || !$bFirst ? ucfirst($strPart) : $strPart; 117 $bFirst = false; 118 } 119 120 return "${strPrefix}${strName}"; 121} 122 123push @EXPORT, qw(bldEnum); 124 125#################################################################################################################################### 126# Quote a list of strings 127#################################################################################################################################### 128sub bldQuoteList 129{ 130 my $ryList = shift; 131 132 my @stryQuoteList; 133 134 foreach my $strItem (@{$ryList}) 135 { 136 push(@stryQuoteList, "\"${strItem}\""); 137 } 138 139 return @stryQuoteList; 140} 141 142push @EXPORT, qw(bldQuoteList); 143 1441; 145