Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use three args open #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added &1
Empty file.
2 changes: 1 addition & 1 deletion adm/cvskwexp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ find(sub {
return if /cvskwexp/;
my $file = $_;
# print "Examining $_\n";
open FILE, "<$_" or die "Cannot open $_";
open FILE, '<', "$_" or die "Cannot open $_";
while(<FILE>) {
die "$file: $_" if /\$\s*Log.*\$/;
}
Expand Down
8 changes: 4 additions & 4 deletions adm/mkppm
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ sub fix_ppd {
###########################################
my($ppd_file) = @_;

open FILE, "<$ppd_file" or die "Cannot open $ppd_file";
open FILE, '<', "$ppd_file" or die "Cannot open $ppd_file";
my $data = join '', <FILE>;
$data =~ s/-\d+\.\d+//g;
close FILE;

open FILE, ">$ppd_file" or die "Cannot open $ppd_file";
open FILE, '>', "$ppd_file" or die "Cannot open $ppd_file";
print FILE $data;
close FILE;
}
Expand All @@ -114,7 +114,7 @@ sub patch_log_dispatch {

# Get rid of Log::Dispatch's annoying user prompting

open FILE, "<Makefile.PL" or die "Cannot open Makefile.PL";
open FILE, '<', "Makefile.PL" or die "Cannot open Makefile.PL";
my $data = join '', <FILE>;
close FILE;

Expand All @@ -124,7 +124,7 @@ sub patch_log_dispatch {
/;
$data =~ s/while\s*\(\s*1\s*\)/while(0)/;

open FILE, ">Makefile.PL" or die "Cannot open Makefile.PL (w)";
open FILE, '>', "Makefile.PL" or die "Cannot open Makefile.PL (w)";
print FILE $data;
close FILE;
}
2 changes: 1 addition & 1 deletion adm/release-graph
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ my($y, $m, $d);

my $last_time = undef;

open FILE, "<Changes";
open FILE, "<", "Changes";
while(<FILE>) {
chomp;

Expand Down
4 changes: 2 additions & 2 deletions adm/sourceforge/updindex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ die "usage: $0 version" unless $version =~ /^[\d.]+\w+$/;

system "git checkout gh-pages" and die $!;

open FILE, "<$IDX" or die "Cannot open $IDX";
open FILE, "<", "$IDX" or die "Cannot open $IDX";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"$IDX" isn't right. Could you fix the various instances of this?

my $data = join '', <FILE>;
close FILE;

Expand All @@ -26,7 +26,7 @@ if(defined $devprod and $devprod =~ /(dev)|(alpha)|(beta)/) {
$data =~ s@<!--DEV-->.*?<!--/DEV-->@<!--DEV-->\n<!--/DEV-->@s;
}

open FILE, ">$IDX" or die "Cannot open $IDX";
open FILE, ">", "$IDX" or die "Cannot open $IDX";
print FILE $data;
close FILE;

Expand Down
2 changes: 1 addition & 1 deletion adm/urlchk
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ for(File::Find::Rule->file()->in(".")) {

next if m#\./blib/#;

open FILE, "<$_" or die "Cannot open $_";
open FILE, "<", "$_" or die "Cannot open $_";
my $data = join '', <FILE>;
close FILE;

Expand Down
4 changes: 2 additions & 2 deletions lib/Log/Log4perl/Appender/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ sub new {
if($self->{recreate_pid_write}) {
print "Creating pid file",
" $self->{recreate_pid_write}\n" if _INTERNAL_DEBUG;
open FILE, ">$self->{recreate_pid_write}" or
open FILE, ">", "$self->{recreate_pid_write}" or
die "Cannot open $self->{recreate_pid_write}";
print FILE "$$\n";
close FILE;
Expand Down Expand Up @@ -148,7 +148,7 @@ sub file_open {
sysopen $fh, "$self->{filename}", $sysmode or
die "Can't sysopen $self->{filename} ($!)";
} else {
open $fh, "$arrows$self->{filename}" or
open $fh, $arrows, "$self->{filename}" or
die "Can't open $self->{filename} ($!)";
}
};
Expand Down
6 changes: 3 additions & 3 deletions lib/Log/Log4perl/FAQ.pm
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,12 @@ for details. Have fun!
Whenever you encounter a fatal error in your application, instead of saying
something like

open FILE, "<blah" or die "Can't open blah -- bailing out!";
open FILE, "<", "blah" or die "Can't open blah -- bailing out!";

just use Log::Log4perl's fatal functions instead:

my $log = get_logger("Some::Package");
open FILE, "<blah" or $log->logdie("Can't open blah -- bailing out!");
open FILE, "<", "blah" or $log->logdie("Can't open blah -- bailing out!");

This will both log the message with priority FATAL according to your current
Log::Log4perl configuration and then call Perl's C<die()>
Expand All @@ -318,7 +318,7 @@ stealth loggers (see L<Log::Log4perl/"Stealth Loggers">),
all you need to do is call

use Log::Log4perl qw(:easy);
open FILE, "<blah" or LOGDIE "Can't open blah -- bailing out!";
open FILE, "<", "blah" or LOGDIE "Can't open blah -- bailing out!";

What can you do if you're using some library which doesn't use Log::Log4perl
and calls C<die()> internally if something goes wrong? Use a
Expand Down
2 changes: 1 addition & 1 deletion lib/Log/Log4perl/InternalDebug.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sub internal_debug_fh {
my($file) = @_;

local($/) = undef;
open FILE, "<$file" or die "Cannot open $file";
open FILE, "<", "$file" or die "Cannot open $file";
my $text = <FILE>;
close FILE;

Expand Down
2 changes: 1 addition & 1 deletion lib/Log/Log4perl/Resurrector.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sub resurrector_fh {
my($file) = @_;

local($/) = undef;
open FILE, "<$file" or die "Cannot open $file";
open FILE, "<", "$file" or die "Cannot open $file";
my $text = <FILE>;
close FILE;

Expand Down
12 changes: 6 additions & 6 deletions t/004Config.t
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ is(Log::Log4perl::Appender::TestBuffer->by_name("A1")->buffer(),
######################################################################
# Test integrity check
######################################################################
open STDERR, ">$TMP_FILE";
open IN, "<$TMP_FILE" or die "Cannot open $TMP_FILE";
open STDERR, ">", "$TMP_FILE";
open IN, "<", "$TMP_FILE" or die "Cannot open $TMP_FILE";
sub readwarn { return (scalar <IN>) || ''; }
END { close IN }

Expand All @@ -222,8 +222,8 @@ unlink $TMP_FILE;
######################################################################
# Misspelled 'rootlogger' (needs to be rootLogger)
######################################################################
open STDERR, ">$TMP_FILE";
open IN, "<$TMP_FILE" or die "Cannot open $TMP_FILE";
open STDERR, ">", "$TMP_FILE";
open IN, "<", "$TMP_FILE" or die "Cannot open $TMP_FILE";

Log::Log4perl->reset();
$Log::Log4perl::Logger::LOGGERS_BY_NAME = {};
Expand All @@ -245,8 +245,8 @@ unlink $TMP_FILE;
######################################################################
# Totally misspelled rootLogger
######################################################################
open STDERR, ">$TMP_FILE";
open IN, "<$TMP_FILE" or die "Cannot open $TMP_FILE";
open STDERR, ">", "$TMP_FILE";
open IN, "<", "$TMP_FILE" or die "Cannot open $TMP_FILE";

Log::Log4perl->reset();
$Log::Log4perl::Logger::LOGGERS_BY_NAME = {};
Expand Down
2 changes: 1 addition & 1 deletion t/005Config-Perl.t
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ my $logger = Log::Log4perl->get_logger("");
my $line = __LINE__ + 1;
$logger->debug("Gurgel");

open LOG, "<$LOGFILE" or die "Cannot open $LOGFILE";
open LOG, "<", "$LOGFILE" or die "Cannot open $LOGFILE";
my $data = <LOG>;

END { close LOG; unlink $LOGFILE; }
Expand Down
2 changes: 1 addition & 1 deletion t/006Config-Java.t
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ push @lines, $line++; $logger->warn("Gurgel");
push @lines, $line++; $logger->error("Gurgel");
push @lines, $line++; $logger->fatal("Gurgel");

open FILE, "<$LOGFILE" or die "Cannot open $LOGFILE";
open FILE, "<", "$LOGFILE" or die "Cannot open $LOGFILE";
my $data = join '', <FILE>;
close FILE;

Expand Down
2 changes: 1 addition & 1 deletion t/007LogPrio.t
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ push @lines, $line++; $logger->warn("Gurgel");
push @lines, $line++; $logger->error("Gurgel");
push @lines, $line++; $logger->fatal("Gurgel");

open FILE, "<$LOGFILE" or die "Cannot open $LOGFILE";
open FILE, "<", "$LOGFILE" or die "Cannot open $LOGFILE";
my $data = join '', <FILE>;
close FILE;

Expand Down
8 changes: 4 additions & 4 deletions t/010JConsole.t
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ Log::Log4perl->init(\$conf);
my $logger = Log::Log4perl->get_logger('cat1');

#hmm, I wonder how portable this is, maybe check $^O first?
open(OLDOUT, ">&STDOUT");
open (TOUCH, ">>$test_logfile");# `touch $test_logfile`;
open(OLDOUT, ">&", STDOUT) or die;
open (TOUCH, ">>", $test_logfile);# `touch $test_logfile`;
close TOUCH;
open(STDOUT, ">$test_logfile") || die "Can't redirect stdout $test_logfile $!";
open(STDOUT, ">", $test_logfile) or die "Can't redirect stdout $test_logfile $!";
select(STDOUT); $| = 1; # make unbuffered

$logger->debug("debugging message 1 ");
Expand All @@ -54,7 +54,7 @@ $logger->warn("warning message 1 ");
$logger->fatal("fatal message 1 ");

close(STDOUT);
open(STDOUT, ">&OLDOUT");
open(STDOUT, ">&", OLDOUT);

my ($result, $expected);

Expand Down
8 changes: 4 additions & 4 deletions t/017Watch.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use Log::Log4perl;
use File::Spec;

sub trunc {
open FILE, ">$_[0]" or die "Cannot open $_[0]";
open FILE, ">", "$_[0]" or die "Cannot open $_[0]";
close FILE;
}

Expand All @@ -35,7 +35,7 @@ log4j.appender.myAppender.filename = $testfile
log4j.appender.myAppender.mode = append

EOL
open (CONF, ">$testconf") || die "can't open $testconf $!";
open (CONF, ">", "$testconf") || die "can't open $testconf $!";
print CONF $conf1;
close CONF;

Expand Down Expand Up @@ -83,7 +83,7 @@ log4j.appender.myAppender.filename = $testfile
log4j.appender.myAppender.mode = append
EOL

open (CONF, ">$testconf") || die "can't open $testconf $!";
open (CONF, ">", "$testconf") || die "can't open $testconf $!";
print CONF $conf2;
close CONF;

Expand Down Expand Up @@ -129,7 +129,7 @@ log4j.appender.myAppender.layout = Log::Log4perl::Layout::SimpleLayout
log4j.appender.myAppender.filename = $testfile
log4j.appender.myAppender.mode = append
EOL
open (CONF, ">$testconf") || die "can't open $testconf $!";
open (CONF, ">", "$testconf") || die "can't open $testconf $!";
print CONF $conf2;
close CONF;

Expand Down
2 changes: 1 addition & 1 deletion t/018Init.t
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $log->info("Shu-wa-chi!");

# Check if both files contain one message each
for my $file ($testfilea, $testfileb) {
open FILE, "<$file" or die "Cannot open $file";
open FILE, "<", "$file" or die "Cannot open $file";
my $content = join '', <FILE>;
close FILE;
ok($content, "INFO - Shu-wa-chi!\n");
Expand Down
4 changes: 2 additions & 2 deletions t/019Warn.t
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ my $TMP_FILE = File::Spec->catfile($WORK_DIR, qw(warnings));
ok(1); # Initialized ok

# Capture STDERR to a temporary file and a filehandle to read from it
open STDERR, ">$TMP_FILE";
open IN, "<$TMP_FILE" or die "Cannot open $TMP_FILE";
open STDERR, ">", "$TMP_FILE";
open IN, "<", "$TMP_FILE" or die "Cannot open $TMP_FILE";
sub readwarn { return scalar <IN>; }

############################################################
Expand Down
16 changes: 8 additions & 8 deletions t/020Easy.t
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ ok(1); # Initialized ok
unlink $TMP_FILE;

# Capture STDOUT to a temporary file and a filehandle to read from it
open STDERR, ">$TMP_FILE";
open STDERR, ">", "$TMP_FILE";
select STDERR; $| = 1; #needed on win32
open IN, "<$TMP_FILE" or die "Cannot open $TMP_FILE";
open IN, "<", "$TMP_FILE" or die "Cannot open $TMP_FILE";
sub readstderr { IN->clearerr(); return join("", <IN>); }

############################################################
Expand All @@ -66,7 +66,7 @@ like($stderr, qr/this also/);
Log::Log4perl->reset();
close IN;
# Reopen stderr
open STDERR, ">&1";
open STDERR, ">", "&1";
unlink $TMP_FILE;

package Bar::Twix;
Expand Down Expand Up @@ -97,7 +97,7 @@ Log::Log4perl->easy_init(
Bar::Mars::crunch();
Bar::Twix::crunch();

open FILE, "<$TMP_FILE" or die "Cannot open $TMP_FILE";
open FILE, "<", "$TMP_FILE" or die "Cannot open $TMP_FILE";
my $data = join '', <FILE>;
close FILE;

Expand All @@ -107,9 +107,9 @@ is($data, "020Easy.t-$line-Bar::Mars::crunch: Mars mjam\nTwix mjam\n");
# LOGDIE and LOGWARN
############################################################
# redir STDERR again
open STDERR, ">$TMP_FILE";
open STDERR, ">", "$TMP_FILE";
select STDERR; $| = 1; #needed on win32
open IN, "<$TMP_FILE" or die "Cannot open $TMP_FILE";
open IN, "<", "$TMP_FILE" or die "Cannot open $TMP_FILE";

Log::Log4perl->easy_init($INFO);
$log = get_logger();
Expand Down Expand Up @@ -172,9 +172,9 @@ close IN;
# LOGCARP and LOGCROAK
############################################################
# redir STDERR again
open STDERR, ">$TMP_FILE";
open STDERR, ">", "$TMP_FILE";
select STDERR; $| = 1; #needed on win32
open IN, "<$TMP_FILE" or die "Cannot open $TMP_FILE";
open IN, "<", "$TMP_FILE" or die "Cannot open $TMP_FILE";

package Whack;
use Log::Log4perl qw(:easy);
Expand Down
10 changes: 5 additions & 5 deletions t/025CustLevels.t
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ $logger->litewarn("this is a LITE warning message (2/3 the calories)");
$logger->info("this info message should not log");


open FILE, "<$LOGFILE" or die "Cannot open $LOGFILE";
open FILE, "<", "$LOGFILE" or die "Cannot open $LOGFILE";
$/ = undef;
my $data = <FILE>;
close FILE;
Expand All @@ -113,7 +113,7 @@ $logger->warn("this is a rootlevel warning message");
$logger->litewarn("this is a rootlevel LITE warning message (2/3 the calories)");
$logger->info("this rootlevel info message should not log");

open FILE, "<$LOGFILE" or die "Cannot open $LOGFILE";
open FILE, "<", "$LOGFILE" or die "Cannot open $LOGFILE";
$/ = undef;
$data = <FILE>;
close FILE;
Expand All @@ -124,7 +124,7 @@ $logger->log($WARN, "a warning message");
$logger->log(Log::Log4perl::Level::to_priority("LITEWARN"), "a LITE warning message");
$logger->log($DEBUG, "an info message, should not log");

open FILE, "<$LOGFILE" or die "Cannot open $LOGFILE";
open FILE, "<", "$LOGFILE" or die "Cannot open $LOGFILE";
$/ = undef;
$data = <FILE>;
close FILE;
Expand All @@ -136,7 +136,7 @@ ok($data, "$result1$result2$result3");
my $debug2 = Log::Log4perl->get_logger("debug2test");
$debug2->debug2("this is a debug2 message");

open FILE, "<$LOGFILE" or die "Cannot open $LOGFILE";
open FILE, "<", "$LOGFILE" or die "Cannot open $LOGFILE";
$/ = undef;
$data = <FILE>;
close FILE;
Expand All @@ -161,7 +161,7 @@ ok(!$logger->is_litewarn);
ok(!$logger->is_info);
$logger->warn("after bumping, warning message");
$logger->litewarn("after bumping, lite warning message, should not log");
open FILE, "<$LOGFILE" or die "Cannot open $LOGFILE";
open FILE, "<", "$LOGFILE" or die "Cannot open $LOGFILE";
$/ = undef;
$data = <FILE>;
close FILE;
Expand Down
Loading