<commit_before>package CCNQ::Install;
# Copyright (C) 2009  <NAME>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
use strict; use warnings;
use Carp;
use File::Spec;
use Digest::SHA1 qw(sha1_hex);

use AnyEvent;
use AnyEvent::DNS;
use AnyEvent::Util;

use Logger::Syslog;

# Where the local configuration information is kept.
use constant CCN => q(/etc/ccn);

# Could use AnyEvent::Util::run_cmd, but there are issues with Cwd.
sub _execute {
  my $context = shift;
  my $command = join(' ',@_);

  my $cv = AnyEvent::Util::run_cmd([@_]);

  $cv->cb( sub {
    my $ret = shift->recv;
    return 1 if $ret == 0;
    # Happily lifted from perlfunc.
    if ($ret == -1) {
        error("Failed to execute ${command}: $!\n");
    }
    elsif ($ret & 127) {
        error(sprintf "Child command ${command} died with signal %d, %s coredump\n",
            ($ret & 127),  ($ret & 128) ? 'with' : 'without');
    }
    else {
        info(sprintf "Child command ${command} exited with value %d\n", $ret >> 8);
    }
    return 0;
  });

  $context->{condvar}->cb($cv);
}

sub first_line_of {
  open(my $fh, '<', $_[0]) or croak "$_[0]: $!";
  my $result = <$fh>;
  chomp($result);
  close($fh) or croak "$_[0]: $!";
  return $result;
}

sub content_of {
  open(my $fh, '<', $_[0]) or croak "$_[0]: $!";
  local $/;
  my $result = <$fh>;
  close($fh) or croak "$_[0]: $!";
  return $result;
}

sub print_to {
  open(my $fh, '>', $_[0]) or croak "$_[0]: $!";
  print $fh $_[1];<commit_msg>run_cmd does not seem to return a $?-like value<commit_after>package CCNQ::Install;
# Copyright (C) 2009  <NAME>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
use strict; use warnings;
use Carp;
use File::Spec;
use Digest::SHA1 qw(sha1_hex);

use AnyEvent;
use AnyEvent::DNS;
use AnyEvent::Util;

use Logger::Syslog;

# Where the local configuration information is kept.
use constant CCN => q(/etc/ccn);

# Could use AnyEvent::Util::run_cmd, but there are issues with Cwd.
sub _execute {
  my $context = shift;
  my $command = join(' ',@_);

  my $cv = AnyEvent::Util::run_cmd([@_]);

  $cv->cb( sub {
    my $ret = shift->recv;
    return 1 if $ret == 0;
    # Happily lifted from perlfunc.
    if ($ret == -1) {
        error("Failed to execute ${command}: $!");
    }
    elsif ($ret & 127) {
        error(sprintf "Child command ${command} died with signal %d, %s coredump",
            ($ret & 127),  ($ret & 128) ? 'with' : 'without');
    }
    else {
        info(sprintf "Child command ${command} exited with value %d", $ret >> 8);
    }
    return 0;
  });

  $context->{condvar}->cb($cv);
}

sub first_line_of {
  open(my $fh, '<', $_[0]) or croak "$_[0]: $!";
  my $result = <$fh>;
  chomp($result);
  close($fh) or croak "$_[0]: $!";
  return $result;
}

sub content_of {
  open(my $fh, '<', $_[0]) or croak "$_[0]: $!";
  local $/;
  my $result = <$fh>;
  close($fh) or croak "$_[0]: $!";
  return $result;
}

sub print_to {
  open(my $fh, '>', $_[0]) or croak "$_[0]: $!";
  print $fh $_[1];
{'fraction_non_alphanumeric': 0.1575408261287224, 'fraction_numerical': 0.01440922190201729, 'mean_word_length': 3.4450373532550693, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5078559', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1407, 'n_words': 520}