App-cloc

 view release on metacpan or  search on metacpan

bin/cloc  view on Meta::CPAN

    if ( ! $HAVE_Parallel_ForkManager ) {
        return 0;
    }

    # Set to number of cores on Linux
    if ( $^O =~ /linux/i and -x '/usr/bin/nproc' ) {
        my $numavcores_linux = `/usr/bin/nproc`;
        chomp $numavcores_linux;
        if ( $numavcores_linux =~ /^\d+$/ ) {
            return $numavcores_linux;
        }
    }

    # Set to number of cores on MacOS
    if ( $^O =~ /darwin/i and -x '/usr/sbin/sysctl') {
       my $numavcores_macos = `/usr/sbin/sysctl -n hw.physicalcpu`;
       chomp $numavcores_macos;
       if ($numavcores_macos =~ /^\d+$/ ) {
           return $numavcores_macos;
       }
    }

    # Disable multiprocessing in other cases
    return 0;
} # 1}}}
sub exclude_autogenerated_files {            # {{{1
    my ($ra_file_list, # in
        $rh_Err      , # in   hash of error codes
        $raa_errors  , # out
        $rh_Ignored  , # out
       ) = @_;
    print "-> exclude_autogenerated_files()\n" if $opt_v > 2;
    my @file_list_minus_autogen = ();
    foreach my $file (@{$ra_file_list}) {
        if ($file !~ /\.go$/) {
            # at the moment, only know Go autogenerated files
            push @file_list_minus_autogen, $file;
            next;
        }
        my $first_line = first_line($file, $rh_Err, $raa_errors);
        if ($first_line =~ m{^//\s+Code\s+generated\s+.*?\s+DO\s+NOT\s+EDIT\.$}) {
            $rh_Ignored->{$file} = 'Go autogenerated file';
        } else {
            # Go, but not autogenerated
            push @file_list_minus_autogen, $file;
        }
    }
    @{$ra_file_list} = @file_list_minus_autogen;
    print "<- exclude_autogenerated_files()\n" if $opt_v > 2;
} # 1}}}
sub count_files {                            # {{{1
    my ($filelist,$counter_type,$language_hash) = @_;
    my @p_errors = ();
    my %p_ignored = ();
    my %p_rbl = ();
    my %p_rbf = ();
    my %Language = %$language_hash;

    foreach my $file (@$filelist) {
        if ( ! $counter_type ) {
            # Multithreading disabled
            $nCounted++;

            printf "Counting:  %d\r", $nCounted
                 unless (!$opt_progress_rate or ($nCounted % $opt_progress_rate));
        }

        next if $Ignored{$file};
        if ($opt_include_lang and not $Include_Language{$Language{$file}}) {
            $p_ignored{$file} = "--include-lang=$Language{$file}";
            next;
        }
        if ($Exclude_Language{$Language{$file}}) {
            $p_ignored{$file} = "--exclude-lang=$Language{$file}";
            next;
        }

        my $Filters_by_Language_Language_file = ! @{$Filters_by_Language{$Language{$file}} };
        if ($Filters_by_Language_Language_file) {
            if ($Language{$file} eq "(unknown)") {
                $p_ignored{$file} = "language unknown (#1)";
            } else {
                $p_ignored{$file} = "missing Filters_by_Language{$Language{$file}}";
            }
            next;
        }

        my ($all_line_count, $blank_count, $comment_count, $code_count);
        if ($opt_use_sloccount and $Language{$file} =~ /^(C|C\+\+|XML|PHP|Pascal|Java)$/) {
            chomp ($blank_count     = `grep -Pcv '\\S' $file`);
            chomp ($all_line_count  = `cat $file | wc -l`);
            if      ($Language{$file} =~ /^(C|C\+\+)$/) {
                $code_count = `cat '$file' | c_count      | head -n 1`;
            } elsif ($Language{$file} eq "XML") {
                $code_count = `cat '$file' | xml_count    | head -n 1`;
            } elsif ($Language{$file} eq "PHP") {
                $code_count = `cat '$file' | php_count    | head -n 1`;
            } elsif ($Language{$file} eq "Pascal") {
                $code_count = `cat '$file' | pascal_count | head -n 1`;
            } elsif ($Language{$file} eq "Java") {
                $code_count = `cat '$file' | java_count   | head -n 1`;
            } else {
                die "SLOCCount match failure: file=[$file] lang=[$Language{$file}]";
            }
            $code_count = substr($code_count, 0, -2);
            $comment_count = $all_line_count - $code_count - $blank_count;
        } else {
            ($all_line_count,
             $blank_count   ,
             $comment_count ,) = call_counter($file, $Language{$file}, \@Errors);
            $code_count = $all_line_count - $blank_count - $comment_count;
        }

        if ($opt_by_file) {
            $p_rbf{$file}{'code'   } = $code_count     ;
            $p_rbf{$file}{'blank'  } = $blank_count    ;
            $p_rbf{$file}{'comment'} = $comment_count  ;
            $p_rbf{$file}{'lang'   } = $Language{$file};
            $p_rbf{$file}{'nFiles' } = 1;
        } else {
            $p_rbf{$file} = 1;  # just keep track of counted files



( run in 2.038 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )