From b3ffb0f0c3c240103a57c98c930d806f748f05a1 Mon Sep 17 00:00:00 2001
From: b <rowerynaksiezycu@gmail.com>
Date: Fri, 14 Mar 2025 03:31:30 +0100
Subject: [PATCH] lists for file open in r/w functions

---
 botm_common.pm | 58 +++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 50 insertions(+), 8 deletions(-)

diff --git a/botm_common.pm b/botm_common.pm
index 5105ed6..938ec96 100644
--- a/botm_common.pm
+++ b/botm_common.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2023, 2024  Balthasar Szczepański
+# Copyright (C) 2023, 2024, 2025  Balthasar Szczepański
 # 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as
@@ -27,7 +27,7 @@ use File::Copy;
 
 use Exporter;
 
-our $VERSION     = '1.1.7';
+our $VERSION     = '1.1.8';
 our @ISA         = qw(Exporter);
 our @EXPORT      = ();
 our @EXPORT_OK   = (
@@ -398,6 +398,7 @@ sub read_data_file {
 		my $file_mode, my $no_fseek,
 	) = @_;
 	my $fh;
+	my @fl;
 	my %data;
 	my $eoh=0;
 	my @list;
@@ -412,6 +413,12 @@ sub read_data_file {
 		$eoh = 1;
 	}
 	
+	# check if $file is a list instead of a single string
+	if (ref($file) eq 'ARRAY') {
+		@fl = @$file;
+		$file = shift @fl;
+	}
+	
 	# check if $file is actually a path or maybe a filehandle
 	# filehandles are references.
 	if (ref($file)) {
@@ -426,7 +433,7 @@ sub read_data_file {
 		if ($file_mode eq '') {
 			$file_mode = '<';
 		}
-		unless (open_encoded($fh, "$file_mode:encoding($encoding)", $file)) {
+		unless (open_encoded($fh, "$file_mode:encoding($encoding)", $file, @fl)) {
 			return %data;
 		}
 	}
@@ -524,11 +531,18 @@ sub write_data_file {
 		my $file_mode, my $no_fseek
 	) = @_;
 	my $fh;
+	my @fl;
 	
 	if ($encoding eq '') {
 		$encoding = 'UTF-8';
 	}
 	
+	# check if $file is a list instead of a single string
+	if (ref($file) eq 'ARRAY') {
+		@fl = @$file;
+		$file = shift @fl;
+	}
+	
 	# check if $file is actually a path or maybe a filehandle
 	# filehandles are references.
 	if (ref($file)) {
@@ -543,7 +557,7 @@ sub write_data_file {
 		if ($file_mode eq '') {
 			$file_mode = '>';
 		}
-		unless (open_encoded($fh, "$file_mode:encoding($encoding)", $file)) {
+		unless (open_encoded($fh, "$file_mode:encoding($encoding)", $file, @fl)) {
 			return 0;
 		}
 	}
@@ -591,11 +605,18 @@ sub write_data_file {
 sub write_postdata_file {
 	(my $file, my $encoding_file, my $encoding_data, my $data) = @_;
 	my $fh;
+	my @fl;
 	
 	if ($encoding_file eq '') {
 		$encoding_file = 'UTF-8';
 	}
 	
+	# check if $file is a list instead of a single string
+	if (ref($file) eq 'ARRAY') {
+		@fl = @$file;
+		$file = shift @fl;
+	}
+	
 	# check if $file is actually a path or maybe a filehandle
 	# filehandles are references.
 	if (ref($file)) {
@@ -605,7 +626,7 @@ sub write_postdata_file {
 		}
 	}
 	else {
-		unless (open_encoded($fh, ">:encoding($encoding_file)", $file)) {
+		unless (open_encoded($fh, ">:encoding($encoding_file)", $file, @fl)) {
 			return 0;
 		}
 	}
@@ -646,6 +667,7 @@ sub write_postdata_file {
 sub read_list_file {
 	(my $file, my $encoding, my $limit) = @_;
 	my $fh;
+	my @fl;
 	my @data;
 	
 	if ($encoding eq '') {
@@ -658,6 +680,12 @@ sub read_list_file {
 		}
 	}
 	
+	# check if $file is a list instead of a single string
+	if (ref($file) eq 'ARRAY') {
+		@fl = @$file;
+		$file = shift @fl;
+	}
+	
 	# check if $file is actually a path or maybe a filehandle
 	# filehandles are references.
 	if (ref($file)) {
@@ -667,7 +695,7 @@ sub read_list_file {
 		}
 	}
 	else {
-		unless (open_encoded($fh, "<:encoding($encoding)", $file)) {
+		unless (open_encoded($fh, "<:encoding($encoding)", $file, @fl)) {
 			return @data;
 		}
 	}
@@ -708,11 +736,18 @@ sub read_list_file {
 sub write_list_file {
 	(my $file, my $encoding, my $data) = @_;
 	my $fh;
+	my @fl;
 	
 	if ($encoding eq '') {
 		$encoding = 'UTF-8';
 	}
 	
+	# check if $file is a list instead of a single string
+	if (ref($file) eq 'ARRAY') {
+		@fl = @$file;
+		$file = shift @fl;
+	}
+	
 	# check if $file is actually a path or maybe a filehandle
 	# filehandles are references.
 	if (ref($file)) {
@@ -722,7 +757,7 @@ sub write_list_file {
 		}
 	}
 	else {
-		unless (open_encoded($fh, ">:encoding($encoding)", $file)) {
+		unless (open_encoded($fh, ">:encoding($encoding)", $file, @fl)) {
 			return 0;
 		}
 	}
@@ -1036,6 +1071,7 @@ sub http_header_content_disposition {
 sub read_header_file {
 	(my $file, my $encoding) = @_;
 	my $fh;
+	my @fl;
 	my %data;
 	my $status_line=1;
 	
@@ -1043,6 +1079,12 @@ sub read_header_file {
 		$encoding = 'utf8';
 	}
 	
+	# check if $file is a list instead of a single string
+	if (ref($file) eq 'ARRAY') {
+		@fl = @$file;
+		$file = shift @fl;
+	}
+	
 	# check if $file is actually a path or maybe a filehandle
 	# filehandles are references.
 	if (ref($file)) {
@@ -1052,7 +1094,7 @@ sub read_header_file {
 		}
 	}
 	else {
-		unless (open_encoded($fh, "<:encoding($encoding)", $file)) {
+		unless (open_encoded($fh, "<:encoding($encoding)", $file, @fl)) {
 			return %data;
 		}
 	}
-- 
2.30.2