blib/lib/Config/IniMan.pm

filter: Statementstmt 11.1% 20 / 179 Branchbran 0.0% 0 / 58 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 22.2% 6 / 27 Podpod 0.0% 0 / 19 totaltotal 8.2% 26 / 317 CC 44 SCAR 30.5
CC
44
Cov
8%
parse
60.9
write
42.0
get
30.0
CRAP 21.1
↑ Summary
1 #=Copyright Infomation
2 #==========================================================
3 #Module Name : Config::IniMan
4 #Program Author : Dr. Ahmed Amin Elsheshtawy, Ph.D. Physics, E.E.
5 #Home Page : http://www.mewsoft.com
6 #Contact Email : support@mewsoft.com
7 #Copyrights © 2014 Mewsoft. All rights reserved.
8 #==========================================================
9 package Config::IniMan;
10  
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 our $VERSION = '1.20';
17 #=========================================================#
18 =encoding utf-8
19  
20 =head1 NAME
21  
22 Config::IniMan - INI file manager object style preserved format and sort order.
23  
24 =head1 SYNOPSIS
25  
26 use Config::IniMan;
27
28 # Create the config object and load it from a file
29 my $config = Config::IniMan->new("sample.ini");
30
31 # Create the config object and load it from a file with specific encoding
32 my $config = Config::IniMan->new("sample.ini", "utf8");
33
34 # Create empty config object
35 my $config = Config::IniMan->new();
36
37 # then load the config file
38 $config->read("sample.ini");
39
40 #read file in specific encoding
41 $config->read("sample.ini", "utf8");
42
43 # parameters values can be obtained as object methods. getter/setter style.
44 # get the parameter 'website' value from current or default section.
45 my $value = $config->website;
46 # same as
47 my $value = $config->get("website");
48 # set parameter 'website' value as a setter object method
49 $config->website("http://mewsoft.com");
50
51 # get parameter value from default or current section
52 my $value = $config->get("name");
53 # get parameter value from a section
54 my $value = $config->get("section", "name");
55 # get parameter value from a section and return default value if it does not exist
56 my $value = $config->get("section", "name", "default");
57
58 # change parameter value in the current or default section
59 $config->set("name", "value");
60 # change parameter value in a section
61 $config->set("section", "name", "value");
62  
63 # add a new section at the end of the file
64 $config->add_section("section");
65
66 #set current active section
67 $config->section(); # set current section to default section
68 $config->section("section");
69 # set current section and get a parameter value from it.
70 $value = $config->section("section")->get("name");
71
72 # get entire section as a hash reference
73 $section = $config->get_section();# default section
74 $section = $config->get_section("section");
75 print $section->{"merchant"};
76
77 # get all sections names
78 @sections = $config->sections();
79
80 # get all section params
81 @params = $config->section_params("section");
82  
83 # get all section values
84 @params = $config->section_values("section");
85  
86 #delete section params
87 $config->delete("section", @name);
88
89 #delete entire section
90 $config->delete_section("section");
91
92 #check if parameter exists
93 $found = $config->exists("name"); # check parameter name exists in the current section.
94 $found = $config->exists("section", "name");
95
96 #check if section exists
97 $found = $config->section_exists("section");
98
99 #Returns entire ini file contents in memory as single string with format preserved.
100 $ini_data = $config->as_string();
101
102 #writes entire ini contents in memory to a file.
103 $config->write(); # save changes to the currently loaded file.
104 $config->write("newfile"); # save as a new file.
105 $config->write("newfile", "utf8"); # save as a new file in different encoding.
106  
107  
108 =head1 DESCRIPTION
109  
110 This module reads and writes INI files in object style and preserves original files sort order, comments, empty lines, and multi lines parameters.
111  
112 It is basically built on the top of using the L<Tie::IxHash> module which implements Perl hashes that preserve the order in which the hash
113 elements were added. The order is not affected when values corresponding to existing sections or parameters are changed.
114  
115 New sections will be added to the end of the current file contents and new parameters will be added to the end of the current section.
116  
117 =head2 INI Format Sample
118  
119 ;default section without name. this line is a comment
120 #this line also is another comment
121 title=Hellow world
122 name=Ahmed Amin Elsheshtawy
123 email=support@mewsoft.com
124 website=http://www.mewsoft.com
125 ;
126 ;line below is empty line and is allowed
127  
128 ;database settings
129 [database]
130 name=blog
131 user=user1234
132 password=blog1234
133  
134 ;admin login
135 [admin]
136 username=admin
137 password=admin123
138  
139 # paypal account setting
140 [payment]
141 merchant=paypal
142 email=support@mewsoft.com
143  
144 [multil-line-data]
145 ftp_msg=This is the ftp address of the domain where\
146 the software will be installed. Either use domain name\
147 or IP address, for example ftp.yourdomain.com is the \
148 ftp address and 234.453.213.32 is the IP number.
149 ;
150 [lastlogin]
151 time=5/9/2014=Friday
152 ;
153 # utf8 Arabic section
154 [عربى]
155 الأسم=أحمد امين الششتاوى
156  
157 =cut
158 #=========================================================#
159 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=3 SCAR=24.8
160 0 my ($self) = shift;
161  
162 0 my ($class, $method) = our $AUTOLOAD =~ /^(.*)::(\w+)$/;
163  
164 0 ▶ if ($self->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can($method)) 0 0 0
165 0 return $self->$method(@_);
166 }
167  
168 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
169 # set parameter value in the current section
170 0 $self->{data}->{$self->{section}}->{$method} = $_[0];
171 0 return $self;
172 }
173 else {
174 # return parameter value from current section
175 0 return $self->{data}->{$self->{section}}->{$method};
176 }
177 }
178 #=========================================================#
179 =head2 new()
180  
181 use Config::IniMan;
182  
183 # Create the config object and load it from a file
184 my $config = Config::IniMan->new("sample.ini");
185  
186 # Create the config object and load it from a file with specific encoding
187 my $config = Config::IniMan->new("sample.ini", "utf8");
188  
189 # Create empty config object
190 my $config = Config::IniMan->new();
191  
192 # then load the config file
193 $config->read("sample.ini");
194  
195 #read file in specific encoding
196 $config->read("sample.ini", "utf8");
197  
198 Create the config object and load it from a file if provided with specific encoding.
199  
200 =cut
201 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
202 0 my ($self, $file, $encoding) = @_;
203
204 0 $self = bless {}, $self;
205
206 0 $self->{encoding} = $encoding;
207 0 $self->{file} = $file;
208 0 $self->{section} = "_"; # default section name
209 0 $self->{data} = {};
210 0 $self->{counter} = 0;
211  
212 0 ▶ $self->read($self->{file}) if ($self->{file});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"file"} 0 0 0
213  
214 0 return $self;
215 }
216 #=========================================================#
217 =head2 read()
218  
219 use Config::IniMan;
220  
221 # Create empty config object
222 my $config = Config::IniMan->new();
223  
224 # then load the config file
225 $config->read("sample.ini");
226  
227 #read file in specific encoding
228 $config->read("sample.ini", "utf8");
229  
230 Read and parse ini file contents in specific encoding.
231  
232 =cut
233 0 ▶sub read {
Subroutine read: not called CC=4 SCAR=30.0
Pod undocumented
234 0 my $self = shift;
235 0 my $file = shift;
236 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
237 0 $self->encoding(shift);
238 }
239  
240 0 ▶ my $encoding = $self->encoding? "<:".$self->encoding : '<';
Branch: 1 branch
BranchTrueFalseTotal
$self->encoding ? : 0 0 0
241 0 local $/= undef;
242
243 0 ▶ open (my $fh, $encoding, $file) or return ("Error reading file $file: $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, $encoding, $file or return "Error reading file ${file}: $!" 0 0 0
244 0 my $content = <$fh>;
245 0 close ($fh);
246  
247 0 $self->parse($content);
248 0 $self->{file} = $file;
249 }
250 #=========================================================#
251 0 ▶sub parse {
Subroutine parse: not called CC=8 SCAR=41.1
Pod undocumented
252 0 my ($self, $content) = @_;
253
254 0 my @lines = split (/(?:\015{1,2}\012|\015|\012)/, $content);
255
256 0 my $section = "_"; # default section name, not written to file
257
258 0 $self->{counter} = 0;
259  
260 1 ▶ no strict 'subs';
Subroutine BEGIN: called CC=1 SCAR=0.0
261
262 # sections sorted hash
263 0 tie %{$self->{data}}, Tie::IxHash;
264
265 # default section variables sorted hash
266 0 tie %{$self->{data}->{$section}}, Tie::IxHash;
267
268 0 my ($name, $value, $multiline);
269  
270 0 $multiline = 0;
271  
272 # process data
273 0 foreach my $line (@lines) {
274
275 0 $self->{counter}++;
276 # keep comments and empty lines
277 0 ▶ if ($line =~ /^\s*(?:\#|\;|$)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*(?:\#|\;|$)/) 0 0 0
278 0 $self->{data}->{$section}->{"__SKIP__$self->{counter}"} = $line;
279 0 next;
280 }
281  
282 # sections names
283 0 ▶ if ($line =~ /^\s*\[\s*(.+?)\s*\]\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*\[\s*(.+?)\s*\]\s*$/) 0 0 0
284 0 $section = $1;
285 # add new section variables sorted hash
286 0 tie %{$self->{data}->{$section}}, Tie::IxHash;
287 0 next;
288 }
289  
290 # section variables key, value pairs key=value
291 0 ▶ if ($multiline) {
Branch: 2 branches
BranchTrueFalseTotal
if ($multiline) { } 0 0 0
elsif ($line =~ /^\s*([^=]+?)\s*=\s*(.*?)\s*$/) { } 0 0 0
292 0 $multiline = 0;
293 0 ▶ if ($line =~ /\\$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\\$/) 0 0 0
294 0 $multiline = 1;
295 0 $line =~ s/\\$//;
296 }
297 0 $self->{data}->{$section}->{$name} .= $line;
298 0 next;
299 }
300 elsif ($line =~ /^\s*([^=]+?)\s*=\s*(.*?)\s*$/) {
301 0 ($name, $value) = ($1, $2);
302 0 $multiline = 0;
303 0 ▶ if ($value =~ /\\$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /\\$/) 0 0 0
304 0 $multiline = 1;
305 0 $value =~ s/\\$//;
306 }
307 0 $self->{data}->{$section}->{$name} = $value;
308 0 next;
309 }
310
311 # TODO error formated line here, heredocs if needed etc
312 }# @lines
313 }
314 #=========================================================#
315 =head2 encoding()
316
317 $encoding = $config->encoding();
318 $config->encoding("utf8"); # set encoding
319  
320 Gets and sets the default file read and write encoding.
321  
322 =cut
323 0 ▶sub encoding {
Subroutine encoding: not called CC=2 SCAR=17.9
Pod undocumented
324 0 my $self = shift;
325 0 ▶ $self->{encoding} = shift if (@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
326 0 $self->{encoding};
327 }
328 #=========================================================#
329 =head2 clear()
330
331 $config->clear();
332  
333 Deletes entire file contents from memory. Does not save to the file.
334  
335 =cut
336 0 ▶sub clear {
Subroutine clear: not called CC=1 SCAR=6.9
Pod undocumented
337 0 my ($self) = @_;
338 0 $self->{data} = {};
339 0 $self->{file} = "";
340 0 $self->{section} = "_";
341 0 $self->{counter} = 0;
342 }
343 #=========================================================#
344 =head2 get()
345  
346 $value = $config->get("name"); # get parameter value from default or current section
347 $value = $config->get("section", "name");
348 $value = $config->get("section", "name", "default");
349  
350 # parameters values can be obtained as object methods. getter/setter style.
351 # get the parameter 'website' value from current or default section.
352 my $value = $config->website;
353 # same as
354 my $value = $config->get("website");
355 # set parameter 'website' value as a setter object method
356 $config->website("http://mewsoft.com");
357  
358 Gets parameter value. Returns the value of a parameter by its name. If you pass only the parameter name, it will search within the
359 current section or the default section. You can pass also a default value to be returned if parameter does not exist.
360  
361 =cut
362 0 ▶sub get {
Subroutine get: not called CC=5 SCAR=34.0
Pod undocumented
363 0 my $self = shift;
364 0 my ($section, $name, $default) = "";
365 0 ▶ if (@_ == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
elsif (@_ == 2) { } 0 0 0
366 0 $name = shift;
367 0 $section = $self->{section};
368 }
369 elsif (@_ == 2) {
370 0 ($section, $name) = @_;
371 }
372 else {
373 0 ($section, $name, $default) = @_;
374 }
375
376 0 ▶ $section ||= $self->{section};
Condition0%0/3
$section ||= $self->{"section"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$section ||= $self->{"section"}
$section $self->{"section"}
Truth table0%0/3
A ||= B
A= $sectionB= $self->{"section"}
ABresult
1X1
011
000
377
378 0 ▶ if (exists $self->{data}->{$section}->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"data"}{$section}{$name}) 0 0 0
379 0 return $self->{data}->{$section}->{$name};
380 }
381  
382 0 return $default;
383 }
384 #=========================================================#
385 =head2 set()
386
387 $config->set("name", "value"); # sets parameter value in the current or default section
388 $config->set("section", "name", "value");
389  
390 # set parameter 'website' value as a setter object method
391 $config->website("http://mewsoft.com");
392  
393 Sets parameter value. Adds new section if section does not exist. This method is chained.
394  
395 =cut
396 0 ▶sub set {
Subroutine set: not called CC=4 SCAR=30.0
Pod undocumented
397 0 my $self = shift;
398 0 my ($section, $name, $value) = "";
399 0 ▶ if (@_ == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) { } 0 0 0
400 0 ($name, $value) = @_;
401 0 $section = $self->{section};
402 }
403 else {
404 0 ($section, $name, $value) = @_;
405 }
406  
407 0 ▶ $section ||= "_";
Condition0%0/2
$section ||= "_"
l!l
00
MC/DC0%0/1
$section ||= "_"
$section
Truth table0%0/2
A
A= $section
Aresult
11
00
408  
409 0 ▶ if (!$self->section_exists($section)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->section_exists($section)) 0 0 0
410 0 $self->add_section($section);
411 }
412  
413 0 $self->{data}->{$section}->{$name} = $value;
414 0 $self;
415 }
416 #=========================================================#
417 =head2 add_section()
418
419 $config->add_section("section");
420  
421 Adds new section to the end of the file if it does not exist. This method is chained.
422  
423 =cut
424 0 ▶sub add_section {
Subroutine add_section: not called CC=3 SCAR=19.6
Pod undocumented
425 0 my ($self, $section) = @_;
426  
427 0 ▶ $section ||= "_";
Condition0%0/2
$section ||= "_"
l!l
00
MC/DC0%0/1
$section ||= "_"
$section
Truth table0%0/2
A
A= $section
Aresult
11
00
428 1 ▶ no strict 'subs';
Subroutine BEGIN: called CC=1 SCAR=0.0
429 0 ▶ if (!$self->section_exists($section)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->section_exists($section)) 0 0 0
430 0 tie %{$self->{data}->{$section}}, Tie::IxHash;
431 }
432
433 0 $self;
434 }
435 #=========================================================#
436 =head2 section()
437
438 $config->section(); # set current section to default section
439 $config->section("section");
440 # set current section and get a parameter value from it.
441 $value = $config->section("section")->get("name");
442  
443 Sets current active section. If empty section name is passed, will set the default section as current one. This method is chained.
444  
445 =cut
446 0 ▶sub section {
Subroutine section: not called CC=3 SCAR=24.8
Pod undocumented
447 0 my ($self, $section) = @_;
448 0 ▶ $section ||= "_";
Condition0%0/2
$section ||= "_"
l!l
00
MC/DC0%0/1
$section ||= "_"
$section
Truth table0%0/2
A
A= $section
Aresult
11
00
449 0 ▶ if ($self->section_exists($section)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->section_exists($section)) 0 0 0
450 0 $self->{section} = $section;
451 0 return $self->{data}->{$section};
452 }
453 }
454 #=========================================================#
455 =head2 get_section()
456
457 $section = $config->get_section();# default section
458 $section = $config->get_section("section");
459 print $section->{"email"};
460  
461 Returns entire section as a hash ref if exists.
462  
463 =cut
464 0 ▶sub get_section {
Subroutine get_section: not called CC=3 SCAR=24.8
Pod undocumented
465 0 my ($self, $section) = @_;
466 0 ▶ $section ||= "_";
Condition0%0/2
$section ||= "_"
l!l
00
MC/DC0%0/1
$section ||= "_"
$section
Truth table0%0/2
A
A= $section
Aresult
11
00
467 0 ▶ if ($self->section_exists($section)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->section_exists($section)) 0 0 0
468 0 return $self->{data}->{$section};
469 }
470 }
471 #=========================================================#
472 =head2 sections()
473
474 @sections = $config->sections();
475  
476 Returns array of sections names in the same sorted order in the file.
477  
478 =cut
479 0 ▶sub sections {
Subroutine sections: not called CC=1 SCAR=6.9
Pod undocumented
480 0 my ($self) = @_;
481 0 (keys %{$self->{data}});
482 }
483 #=========================================================#
484 =head2 section_params()
485
486 @params = $config->section_params("section");
487  
488 Returns array of section parameters names in the same sorted order in the file.
489  
490 =cut
491 0 ▶sub section_params {
Subroutine section_params: not called CC=2 SCAR=17.9
Pod undocumented
492 0 my ($self, $section) = @_;
493
494 0 ▶ $section ||= $self->{section};
Condition0%0/3
$section ||= $self->{"section"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$section ||= $self->{"section"}
$section $self->{"section"}
Truth table0%0/3
A ||= B
A= $sectionB= $self->{"section"}
ABresult
1X1
011
000
495 0 (keys %{$self->{data}->{$section}});
496 }
497 #=========================================================#
498 =head2 section_values()
499
500 @values = $config->section_values(); # get current or default section values
501 @values = $config->section_values("section");
502  
503 Returns array of section parameters values in the same sorted order in the file.
504  
505 =cut
506 0 ▶sub section_values {
Subroutine section_values: not called CC=1 SCAR=6.9
Pod undocumented
507 0 my ($self, $section) = @_;
508 0 (values %{$self->{data}->{$section}});
509 }
510 #=========================================================#
511 =head2 delete()
512
513 $config->delete("section", @name);
514  
515 Delete section parameters. This method is chained.
516  
517 =cut
518 0 ▶sub delete {
Subroutine delete: not called CC=3 SCAR=24.8
Pod undocumented
519 0 my ($self, $section, @name) = @_;
520 0 ▶ $section ||= "_";
Condition0%0/2
$section ||= "_"
l!l
00
MC/DC0%0/1
$section ||= "_"
$section
Truth table0%0/2
A
A= $section
Aresult
11
00
521 0 delete $self->{data}->{$section}->{$_} for @name;
522 0 $self;
523 }
524 #=========================================================#
525 =head2 delete_section()
526
527 $config->delete_section();# delete default section
528 $config->delete_section("section");
529  
530 Delete entire section if it exist. This method is chained.
531  
532 =cut
533 0 ▶sub delete_section {
Subroutine delete_section: not called CC=2 SCAR=17.9
Pod undocumented
534 0 my ($self, $section) = @_;
535 0 ▶ $section ||= "_";
Condition0%0/2
$section ||= "_"
l!l
00
MC/DC0%0/1
$section ||= "_"
$section
Truth table0%0/2
A
A= $section
Aresult
11
00
536 0 delete $self->{data}->{$section};
537 0 $self;
538 }
539 #=========================================================#
540 =head2 exists()
541
542 $found = $config->exists("name"); # check parameter name exists in the current section.
543 $found = $config->exists("section", "name");
544  
545 Checks if parameter exists. If no section passed, it will check in the current of default section.
546  
547 =cut
548 0 ▶sub exists {
Subroutine exists: not called CC=3 SCAR=24.8
Pod undocumented
549 0 my $self = shift;
550 0 my ($section, $name);
551 0 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
552 0 $name = shift;
553 0 $section = $self->{section};
554 }
555 else {
556 0 ($section, $name) = @_;
557 }
558 0 ▶ $section ||= "_";
Condition0%0/2
$section ||= "_"
l!l
00
MC/DC0%0/1
$section ||= "_"
$section
Truth table0%0/2
A
A= $section
Aresult
11
00
559 0 exists $self->{data}->{$section}->{$name};
560 }
561 #=========================================================#
562 =head2 section_exists()
563
564 $found = $config->section_exists("section");
565  
566 Checks if section exists.
567  
568 =cut
569 0 ▶sub section_exists {
Subroutine section_exists: not called CC=2 SCAR=17.9
Pod undocumented
570 0 my ($self, $section) = @_;
571 0 ▶ $section ||= "_";
Condition0%0/2
$section ||= "_"
l!l
00
MC/DC0%0/1
$section ||= "_"
$section
Truth table0%0/2
A
A= $section
Aresult
11
00
572 0 exists $self->{data}->{$section};
573 }
574 #=========================================================#
575 =head2 as_string()
576
577 $ini_data = $config->as_string();
578  
579 Returns entire ini file contents in memory as single string with format preserved.
580  
581 =cut
582 0 ▶sub as_string {
Subroutine as_string: not called CC=5 SCAR=34.0
Pod undocumented
583 0 my ($self) = @_;
584
585 0 my $content = "";
586
587 0 my $v;
588 0 foreach my $section (keys %{$self->{data}}) {
589 0 ▶ $content .= "[$section]\n" unless ($section eq "_");
Branch: 1 branch
BranchTrueFalseTotal
unless $section eq "_" 0 0 0
590  
591 0 foreach my $k (keys %{$self->{data}->{$section}}) {
592 0 $v =$self->{data}->{$section}->{$k};
593 0 ▶ if ($k =~ /^__SKIP__\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^__SKIP__\d+$/) { } 0 0 0
594 0 $content .= "$v\n";
595 0 next;
596 }
597 else {
598 0 $content .= "$k=$v\n";
599 }
600 }
601 }
602
603 0 return $content;
604 }
605 #=========================================================#
606 =head2 write()
607
608 $config->write(); # save changes to the currently loaded file.
609 $config->write("newfile"); # save as a new file.
610 $config->write("newfile", "utf8"); # save as a new file in different encoding.
611  
612 Writes entire ini file contents in memory to file.
613  
614 =cut
615 0 ▶sub write {
Subroutine write: not called CC=6 SCAR=37.4
Pod undocumented
616 0 my $self= shift;
617 0 ▶ my $file = shift if (@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
618 0 ▶ $self->encoding(shift) if (@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
619
620 0 ▶ $file or return ("Empty file name during writing file: $!");
Branch: 1 branch
BranchTrueFalseTotal
$file or return "Empty file name during writing file: $!" 0 0 0
621  
622 0 ▶ my $encoding = $self->encoding? ">:".$self->encoding : '>';
Branch: 1 branch
BranchTrueFalseTotal
$self->encoding ? : 0 0 0
623 0 local $/= undef;
624
625 0 ▶ open(my $fh, $encoding, $file) or return ("Error writing file $file: $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, $encoding, $file or return "Error writing file ${file}: $!" 0 0 0
626 0 print $fh $self->as_string;
627 0 close($fh);
628 }
629 #=========================================================#
630 #TODO
631 #sub rename {
632 #my ($self, $section, $key, $newkey) = @_;
633 #}
634 #=========================================================#
635 #TODO
636 #sub rename_section {
637 #my ($self, $section, $newsection) = @_;
638 #}
639 #=========================================================#
640 #TODO
641 #sub set_section_comment {
642 #my ($self, $section, @comment) = @_;
643 #}
644 #=========================================================#
645 #TODO
646 #sub get_section_comment {
647 #my ($self, $section, @comment) = @_;
648 #}
649 #=========================================================#
650 #TODO
651 #sub del_section_comment {
652 #my ($self, $section, @comment) = @_;
653 #}
654 #=========================================================#
655 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
656 }
657 #=========================================================#
658 #=========================================================#
659 1 1;
660  
661  
662 =head1 Bugs
663  
664 This project is available on github at L<https://github.com/mewsoft> .
665  
666 =head1 SEE ALSO
667  
668 L<Config::Tiny>
669 L<Config::IniFiles>
670 L<Config::INI>
671 L<Config::INIPlus>
672 L<Config::Any>
673 L<Config::General>
674  
675 =head1 AUTHOR
676  
677 Ahmed Amin Elsheshtawy, احمد امين الششتاوى <support@mewsoft.com>
678 Website: http://www.mewsoft.com
679  
680 =head1 COPYRIGHT AND LICENSE
681  
682 Copyright (C) 2014 by Dr. Ahmed Amin Elsheshtawy support@mewsoft.com,
683 L<http://www.mewsoft.com>
684  
685 This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
686  
687 =cut
688  
↑ Summary