| 1 | #!/usr/local/bin/perl | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | 9 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 9 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | |||||||||||||||||||||||
| 6 | 9 | ▶ | use SPVM::Global; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | 9 | ▶ | use SPVM::Builder::Util; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 8 | 9 | ▶ | use SPVM::Builder::DependencyAnalyzer; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | 9 | SPVM::Builder::Util::getopt | |||||||||||||||||||||
| 11 | # spvm,spvmcc,spvmdeps common | ||||||||||||||||||||||
| 12 | 'h|help' => \my $help, | ||||||||||||||||||||||
| 13 | 'v|version' => \my $show_version, | ||||||||||||||||||||||
| 14 | 'I=s' => \my @spvm_include_dirs, | ||||||||||||||||||||||
| 15 | 'Mblib' => \my $blib, | ||||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | # spvmdeps only | ||||||||||||||||||||||
| 18 | 'json' => \my $json_option_on, | ||||||||||||||||||||||
| 19 | 'cpanm' => \my $cpanm_option_on, | ||||||||||||||||||||||
| 20 | 'cpanfile' => \my $cpanfile_option_on, | ||||||||||||||||||||||
| 21 | 'with-version' => \my $with_version_option_on, | ||||||||||||||||||||||
| 22 | 'exclude=s' => \my @excluded_class_names, | ||||||||||||||||||||||
| 23 | 'resource-info' => \my $show_resource_info, | ||||||||||||||||||||||
| 24 | ; | ||||||||||||||||||||||
| 25 | |||||||||||||||||||||||
| 26 | 8 | ▶ | if ($help) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 27 | 0 | print SPVM::Builder::Util::extract_usage; | |||||||||||||||||||||
| 28 | 0 | exit 0; | |||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||
| 30 | elsif ($show_version) { | ||||||||||||||||||||||
| 31 | 0 | my $version_string = "spvmdeps v$SPVM::VERSION"; | |||||||||||||||||||||
| 32 | 0 | print "$version_string\n"; | |||||||||||||||||||||
| 33 | 0 | exit 0; | |||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||
| 35 | |||||||||||||||||||||||
| 36 | 8 | my $script_name = shift; | |||||||||||||||||||||
| 37 | |||||||||||||||||||||||
| 38 | 8 | ▶ | unless (defined $script_name) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 39 | 0 | die "[spvmdeps command]spvmdeps command needs SCRIPT_NAME." | |||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||
| 41 | |||||||||||||||||||||||
| 42 | 8 | my $source = ""; | |||||||||||||||||||||
| 43 | 8 | eval { $source = SPVM::Builder::Util::slurp_binary($script_name); }; | |||||||||||||||||||||
| 44 | |||||||||||||||||||||||
| 45 | 8 | SPVM::Builder::Util::setup_spvm_command_environment($script_name, $source, $blib, \@spvm_include_dirs, undef, undef, undef, undef, undef); | |||||||||||||||||||||
| 46 | |||||||||||||||||||||||
| 47 | 8 | my $dependency_analyzer = SPVM::Builder::DependencyAnalyzer->new( | |||||||||||||||||||||
| 48 | script_name => $script_name, | ||||||||||||||||||||||
| 49 | with_version => $with_version_option_on, | ||||||||||||||||||||||
| 50 | excluded_class_names => \@excluded_class_names, | ||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||
| 52 | |||||||||||||||||||||||
| 53 | 8 | ▶ | if ($show_resource_info) { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 54 | |||||||||||||||||||||||
| 55 | 1 | my $resource_info = $dependency_analyzer->dump_resource_info; | |||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | 1 | print $resource_info; | |||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||
| 59 | elsif ($cpanm_option_on) { | ||||||||||||||||||||||
| 60 | |||||||||||||||||||||||
| 61 | 0 | my $cpanm_commands = $dependency_analyzer->to_cpanm_commands; | |||||||||||||||||||||
| 62 | |||||||||||||||||||||||
| 63 | 0 | my $cpanm_commands_lines = SPVM::Builder::DependencyAnalyzer->to_lines($cpanm_commands); | |||||||||||||||||||||
| 64 | |||||||||||||||||||||||
| 65 | 0 | print $cpanm_commands_lines; | |||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||
| 67 | elsif ($cpanfile_option_on) { | ||||||||||||||||||||||
| 68 | |||||||||||||||||||||||
| 69 | 2 | my $cpanfile_commands = $dependency_analyzer->to_cpanfile_commands; | |||||||||||||||||||||
| 70 | |||||||||||||||||||||||
| 71 | 2 | my $cpanfile_commands_lines = SPVM::Builder::DependencyAnalyzer->to_lines($cpanfile_commands); | |||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | 2 | print $cpanfile_commands_lines; | |||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||
| 75 | elsif ($json_option_on) { | ||||||||||||||||||||||
| 76 | 2 | my $json = $dependency_analyzer->to_json; | |||||||||||||||||||||
| 77 | |||||||||||||||||||||||
| 78 | 2 | print $json; | |||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||
| 80 | else { | ||||||||||||||||||||||
| 81 | 3 | my $class_names = $dependency_analyzer->to_class_names; | |||||||||||||||||||||
| 82 | |||||||||||||||||||||||
| 83 | 3 | my $class_names_lines = SPVM::Builder::DependencyAnalyzer->to_lines($class_names); | |||||||||||||||||||||
| 84 | |||||||||||||||||||||||
| 85 | 3 | print $class_names_lines; | |||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||
| 87 | |||||||||||||||||||||||
| 88 | =encoding utf8 | ||||||||||||||||||||||
| 89 | |||||||||||||||||||||||
| 90 | =head1 Name | ||||||||||||||||||||||
| 91 | |||||||||||||||||||||||
| 92 | spvmdeps - Class Dependencies Analyzer | ||||||||||||||||||||||
| 93 | |||||||||||||||||||||||
| 94 | =head1 Description | ||||||||||||||||||||||
| 95 | |||||||||||||||||||||||
| 96 | C<spvmdeps> command is a class dependencies analyzer. | ||||||||||||||||||||||
| 97 | |||||||||||||||||||||||
| 98 | =head1 Usage | ||||||||||||||||||||||
| 99 | |||||||||||||||||||||||
| 100 | Usage: spvmdeps [OPTIONS] SCRIPT_NAME | ||||||||||||||||||||||
| 101 | |||||||||||||||||||||||
| 102 | spvmdeps myapp.spvm | ||||||||||||||||||||||
| 103 | |||||||||||||||||||||||
| 104 | spvmdeps --with-version myapp.spvm | ||||||||||||||||||||||
| 105 | |||||||||||||||||||||||
| 106 | spvmdeps --cpanm --with-version myapp.spvm | ||||||||||||||||||||||
| 107 | |||||||||||||||||||||||
| 108 | spvmdeps --cpanfile --with-version myapp.spvm | ||||||||||||||||||||||
| 109 | |||||||||||||||||||||||
| 110 | Options: | ||||||||||||||||||||||
| 111 | -h, --help Shows this message | ||||||||||||||||||||||
| 112 | -v, --version Shows the version | ||||||||||||||||||||||
| 113 | -I DIRECTORY Adds a include directory | ||||||||||||||||||||||
| 114 | -Mblib Same as "-Mblib" in perl | ||||||||||||||||||||||
| 115 | |||||||||||||||||||||||
| 116 | --json Prints JSON that contains all dependent class information. | ||||||||||||||||||||||
| 117 | --cpanm Prints cpanm commands that contains dependent cpan modules | ||||||||||||||||||||||
| 118 | --cpanfile Prints cpanfile that contains dependent cpan modules | ||||||||||||||||||||||
| 119 | --with-version Output(default, --cpanm, --json) contains version information. | ||||||||||||||||||||||
| 120 | --exclude CLASS_NAME Excludes a class name. This option can be used repeatedly. | ||||||||||||||||||||||
| 121 | --resource-info Shows config files of dependent resources | ||||||||||||||||||||||
| 122 | |||||||||||||||||||||||
| 123 | =head1 Details | ||||||||||||||||||||||
| 124 | |||||||||||||||||||||||
| 125 | spvmdeps [OPTIONS] SCRIPT_NAME | ||||||||||||||||||||||
| 126 | |||||||||||||||||||||||
| 127 | The C<spvmdeps> command prints class dependency information. | ||||||||||||||||||||||
| 128 | |||||||||||||||||||||||
| 129 | Output Examples: | ||||||||||||||||||||||
| 130 | |||||||||||||||||||||||
| 131 | Sys | ||||||||||||||||||||||
| 132 | Regex | ||||||||||||||||||||||
| 133 | Foo | ||||||||||||||||||||||
| 134 | Bar | ||||||||||||||||||||||
| 135 | |||||||||||||||||||||||
| 136 | # --with-version | ||||||||||||||||||||||
| 137 | Sys 1.201 | ||||||||||||||||||||||
| 138 | Regex 0.980 | ||||||||||||||||||||||
| 139 | Foo (version_from Sys) | ||||||||||||||||||||||
| 140 | Bar | ||||||||||||||||||||||
| 141 | |||||||||||||||||||||||
| 142 | I<OPTIONS> are L<options|/"Options">. | ||||||||||||||||||||||
| 143 | |||||||||||||||||||||||
| 144 | I<SCRIPT_NAME> is a script name that contains a L<bootstrap method|SPVM::Document::Language::Class/"Bootstrap Method"> in an L<anon class|SPVM::Document::Language::Class/"Anon Class">. | ||||||||||||||||||||||
| 145 | |||||||||||||||||||||||
| 146 | class { | ||||||||||||||||||||||
| 147 | static method main : void () { | ||||||||||||||||||||||
| 148 | |||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||
| 151 | |||||||||||||||||||||||
| 152 | See L<Class Search Directories|SPVM::Document::Language::Class/"Class Search Directories"> about default class search directories. | ||||||||||||||||||||||
| 153 | |||||||||||||||||||||||
| 154 | =head1 Options | ||||||||||||||||||||||
| 155 | |||||||||||||||||||||||
| 156 | =head2 --help | ||||||||||||||||||||||
| 157 | |||||||||||||||||||||||
| 158 | See L<spvm/"--help">. | ||||||||||||||||||||||
| 159 | |||||||||||||||||||||||
| 160 | =head2 -h | ||||||||||||||||||||||
| 161 | |||||||||||||||||||||||
| 162 | -h | ||||||||||||||||||||||
| 163 | |||||||||||||||||||||||
| 164 | See L<spvm/"-h">. | ||||||||||||||||||||||
| 165 | |||||||||||||||||||||||
| 166 | =head2 --version | ||||||||||||||||||||||
| 167 | |||||||||||||||||||||||
| 168 | See L<spvm/"--version">. | ||||||||||||||||||||||
| 169 | |||||||||||||||||||||||
| 170 | =head2 -v | ||||||||||||||||||||||
| 171 | |||||||||||||||||||||||
| 172 | -v | ||||||||||||||||||||||
| 173 | |||||||||||||||||||||||
| 174 | See L<spvm/"-v">. | ||||||||||||||||||||||
| 175 | |||||||||||||||||||||||
| 176 | =head2 -I | ||||||||||||||||||||||
| 177 | |||||||||||||||||||||||
| 178 | -I DIR | ||||||||||||||||||||||
| 179 | |||||||||||||||||||||||
| 180 | See L<spvm/"-I">. | ||||||||||||||||||||||
| 181 | |||||||||||||||||||||||
| 182 | =head2 -B | ||||||||||||||||||||||
| 183 | |||||||||||||||||||||||
| 184 | -B DIR | ||||||||||||||||||||||
| 185 | |||||||||||||||||||||||
| 186 | See L<spvm/"-B">. | ||||||||||||||||||||||
| 187 | |||||||||||||||||||||||
| 188 | =head2 -Mblib | ||||||||||||||||||||||
| 189 | |||||||||||||||||||||||
| 190 | -Mblib | ||||||||||||||||||||||
| 191 | |||||||||||||||||||||||
| 192 | See L<spvm/"-Mblib">. | ||||||||||||||||||||||
| 193 | |||||||||||||||||||||||
| 194 | =head2 --json | ||||||||||||||||||||||
| 195 | |||||||||||||||||||||||
| 196 | --json | ||||||||||||||||||||||
| 197 | |||||||||||||||||||||||
| 198 | Prints JSON that contains all dependent class information. | ||||||||||||||||||||||
| 199 | |||||||||||||||||||||||
| 200 | Output Examples: | ||||||||||||||||||||||
| 201 | |||||||||||||||||||||||
| 202 | [ | ||||||||||||||||||||||
| 203 | {"class_name":"Address"}, | ||||||||||||||||||||||
| 204 | {"class_name":"Bool"}, | ||||||||||||||||||||||
| 205 | {"class_name":"Byte"}, | ||||||||||||||||||||||
| 206 | {"class_name":"CommandInfo"}, | ||||||||||||||||||||||
| 207 | {"class_name":"Double"}, | ||||||||||||||||||||||
| 208 | {"class_name":"Error"}, | ||||||||||||||||||||||
| 209 | {"class_name":"Error::Compile"}, | ||||||||||||||||||||||
| 210 | {"class_name":"Error::NotSupported"}, | ||||||||||||||||||||||
| 211 | {"class_name":"Error::System"}, | ||||||||||||||||||||||
| 212 | {"class_name":"Float"}, | ||||||||||||||||||||||
| 213 | {"class_name":"Int"}, | ||||||||||||||||||||||
| 214 | {"class_name":"Long"}, | ||||||||||||||||||||||
| 215 | {"class_name":"SPVM"}, | ||||||||||||||||||||||
| 216 | {"class_name":"Short"}, | ||||||||||||||||||||||
| 217 | {"class_name":"TestCase::NativeAPI2"}, | ||||||||||||||||||||||
| 218 | {"class_name":"TestCase::Precompile"} | ||||||||||||||||||||||
| 219 | ] | ||||||||||||||||||||||
| 220 | |||||||||||||||||||||||
| 221 | # --with-version | ||||||||||||||||||||||
| 222 | [ | ||||||||||||||||||||||
| 223 | {"class_name":"Address","version_from":"SPVM"}, | ||||||||||||||||||||||
| 224 | {"class_name":"Bool","version_from":"SPVM"}, | ||||||||||||||||||||||
| 225 | {"class_name":"Byte","version_from":"SPVM"}, | ||||||||||||||||||||||
| 226 | {"class_name":"CommandInfo","version_from":"SPVM"}, | ||||||||||||||||||||||
| 227 | {"class_name":"Double","version_from":"SPVM"}, | ||||||||||||||||||||||
| 228 | {"class_name":"Error","version_from":"SPVM"}, | ||||||||||||||||||||||
| 229 | {"class_name":"Error::Compile","version_from":"SPVM"}, | ||||||||||||||||||||||
| 230 | {"class_name":"Error::NotSupported","version_from":"SPVM"}, | ||||||||||||||||||||||
| 231 | {"class_name":"Error::System","version_from":"SPVM"}, | ||||||||||||||||||||||
| 232 | {"class_name":"Float","version_from":"SPVM"}, | ||||||||||||||||||||||
| 233 | {"class_name":"Int","version_from":"SPVM"}, | ||||||||||||||||||||||
| 234 | {"class_name":"Long","version_from":"SPVM"}, | ||||||||||||||||||||||
| 235 | {"class_name":"SPVM","version":"0.990036"}, | ||||||||||||||||||||||
| 236 | {"class_name":"Short","version_from":"SPVM"}, | ||||||||||||||||||||||
| 237 | {"class_name":"TestCase::NativeAPI2","version":"1.002"}, | ||||||||||||||||||||||
| 238 | {"class_name":"TestCase::Precompile","version":"2.005"} | ||||||||||||||||||||||
| 239 | ] | ||||||||||||||||||||||
| 240 | |||||||||||||||||||||||
| 241 | =head2 --cpanm | ||||||||||||||||||||||
| 242 | |||||||||||||||||||||||
| 243 | --cpanm | ||||||||||||||||||||||
| 244 | |||||||||||||||||||||||
| 245 | Prints cpanm commands that contains dependent CPAN modules. Classes its version is specified are treated as dependent CPAN modules. | ||||||||||||||||||||||
| 246 | |||||||||||||||||||||||
| 247 | Output Examples: | ||||||||||||||||||||||
| 248 | |||||||||||||||||||||||
| 249 | cpanm SPVM | ||||||||||||||||||||||
| 250 | cpanm SPVM::Sys | ||||||||||||||||||||||
| 251 | cpanm SPVM::Regex | ||||||||||||||||||||||
| 252 | |||||||||||||||||||||||
| 253 | # --with-version | ||||||||||||||||||||||
| 254 | cpanm SPVM@1.001 | ||||||||||||||||||||||
| 255 | cpanm SPVM::Sys@1.201 | ||||||||||||||||||||||
| 256 | cpanm SPVM::Regex@0.980 | ||||||||||||||||||||||
| 257 | |||||||||||||||||||||||
| 258 | =head2 --cpanfile | ||||||||||||||||||||||
| 259 | |||||||||||||||||||||||
| 260 | --cpanfile | ||||||||||||||||||||||
| 261 | |||||||||||||||||||||||
| 262 | Prints cpanfile that contains dependent CPAN modules. Classes its version is specified are treated as dependent CPAN modules. | ||||||||||||||||||||||
| 263 | |||||||||||||||||||||||
| 264 | Output Examples: | ||||||||||||||||||||||
| 265 | |||||||||||||||||||||||
| 266 | requires 'SPVM'; | ||||||||||||||||||||||
| 267 | requires 'SPVM::Sys'; | ||||||||||||||||||||||
| 268 | requires 'SPVM::Regex'; | ||||||||||||||||||||||
| 269 | |||||||||||||||||||||||
| 270 | # --with-version | ||||||||||||||||||||||
| 271 | requires 'SPVM', '== 1.001'; | ||||||||||||||||||||||
| 272 | requires 'SPVM::Sys', '== 1.201'; | ||||||||||||||||||||||
| 273 | requires 'SPVM::Regex', '== 0.980'; | ||||||||||||||||||||||
| 274 | |||||||||||||||||||||||
| 275 | =head2 --with-version | ||||||||||||||||||||||
| 276 | |||||||||||||||||||||||
| 277 | --with-version | ||||||||||||||||||||||
| 278 | |||||||||||||||||||||||
| 279 | Output(default, L</"--cpanm">, L</"--cpanfile">, L</"--json">) contains version information. | ||||||||||||||||||||||
| 280 | |||||||||||||||||||||||
| 281 | =head2 --exclude | ||||||||||||||||||||||
| 282 | |||||||||||||||||||||||
| 283 | --exclude=<class_name> | ||||||||||||||||||||||
| 284 | |||||||||||||||||||||||
| 285 | Excludes a class name. This option can be used repeatedly. | ||||||||||||||||||||||
| 286 | |||||||||||||||||||||||
| 287 | Examples: | ||||||||||||||||||||||
| 288 | |||||||||||||||||||||||
| 289 | --exclude TestCase::Foo | ||||||||||||||||||||||
| 290 | |||||||||||||||||||||||
| 291 | Wildcard C<*> can be used. | ||||||||||||||||||||||
| 292 | |||||||||||||||||||||||
| 293 | --exclude TestCase::* | ||||||||||||||||||||||
| 294 | |||||||||||||||||||||||
| 295 | =head2 --resource-info | ||||||||||||||||||||||
| 296 | |||||||||||||||||||||||
| 297 | --resource-info | ||||||||||||||||||||||
| 298 | |||||||||||||||||||||||
| 299 | Shows all config files loading resources. | ||||||||||||||||||||||
| 300 | |||||||||||||||||||||||
| 301 | =head1 lib Directive | ||||||||||||||||||||||
| 302 | |||||||||||||||||||||||
| 303 | If the source code specified by I<SCRIPT_NAME> contains lib directives, The directories specified by lib directive is prepeneded to L<class search directories|SPVM::Document::Language::Class/"Class Search Directories">. | ||||||||||||||||||||||
| 304 | |||||||||||||||||||||||
| 305 | #lib "$FindBin::Bin/lib" | ||||||||||||||||||||||
| 306 | |||||||||||||||||||||||
| 307 | class { | ||||||||||||||||||||||
| 308 | |||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||
| 310 | |||||||||||||||||||||||
| 311 | This directories specified by lib directive is placed after the directories specified by L</"-I"> option. | ||||||||||||||||||||||
| 312 | |||||||||||||||||||||||
| 313 | =head1 Copyright & License | ||||||||||||||||||||||
| 314 | |||||||||||||||||||||||
| 315 | Copyright 2023 Yuki Kimoto. All Rights Reserved. | ||||||||||||||||||||||
| 316 | |||||||||||||||||||||||
| 317 | MIT License. | ||||||||||||||||||||||