Debian Codegraph @

lib/Config/IniFiles.pm

raw
1 package Config::IniFiles;
2
3 require 5.008;
4 use strict;
5 use warnings;
6
7 our $VERSION = '3.003000';
8 use Carp;
9 use Symbol 'gensym', 'qualify_to_ref'; # For the 'any data type' hack
10 use Fcntl qw( SEEK_SET SEEK_CUR );
11
12 use List::Util 1.33 qw(any none);
13
14 use File::Basename qw( dirname );
15 use File::Temp qw/ tempfile /;
16
17 @Config::IniFiles::errors = ();
18
19 # $Header: /home/shlomi/progs/perl/cpan/Config/IniFiles/config-inifiles-cvsbackup/config-inifiles/IniFiles.pm,v 2.41 2003-12-08 10:50:56 domq Exp $
20
21
22 sub _nocase
23 {
24 my $self = shift;
25
26 if (@_)
27 {
28 $self->{nocase} = ( shift(@_) ? 1 : 0 );
29 }
30
31 return $self->{nocase};
32 }
33
34 sub _is_parm_in_sect
35 {
36 my ( $self, $sect, $parm ) = @_;
37
38 return any { $_ eq $parm } @{ $self->{myparms}{$sect} };
39 }
40
41 sub new
42 {
43 my $class = shift;
44 my %parms = @_;
45
46 my $errs = 0;
47 my @groups = ();
48
49 my $self = bless {
50 default => '',
51 fallback => undef,
52 fallback_used => 0,
53 imported => undef,
54 v => {},
55 cf => undef,
56 nomultiline => 0,
57 handle_trailing_comment => 0,
58 }, $class;
59
60 if ( ref( $parms{-import} )
61 && ( $parms{-import}->isa('Config::IniFiles') ) )
62 {
63 $self->{imported} = $parms{-import}; # ReadConfig will load the data
64 $self->{negativedeltas} = 1;
65 }
66 elsif ( defined $parms{-import} )
67 {
68 carp "Invalid -import value \"$parms{-import}\" was ignored.";
69 } # end if
70 delete $parms{-import};
71
72 # Copy the original parameters so we
73 # can use them when we build new sections
74 %{ $self->{startup_settings} } = %parms;
75
76 # Parse options
77 my ( $k, $v );
78 $self->_nocase(0);
79
80 # Handle known parameters first in this order,
81 # because each() could return parameters in any order
82 if ( defined( $v = delete $parms{'-file'} ) )
83 {
84 # Should we be pedantic and check that the file exists?
85 # .. no, because now it could be a handle, IO:: object or something else
86 $self->{cf} = $v;
87 }
88 if ( defined( $v = delete $parms{'-nocase'} ) )
89 {
90 $self->_nocase($v);
91 }
92 if ( defined( $v = delete $parms{'-default'} ) )
93 {
94 $self->{default} = $self->_nocase ? lc($v) : $v;
95 }
96 if ( defined( $v = delete $parms{'-fallback'} ) )
97 {
98 $self->{fallback} = $self->_nocase ? lc($v) : $v;
99 }
100 if ( defined( $v = delete $parms{'-reloadwarn'} ) )
101 {
102 $self->{reloadwarn} = $v ? 1 : 0;
103 }
104 if ( defined( $v = delete $parms{'-nomultiline'} ) )
105 {
106 $self->{nomultiline} = $v ? 1 : 0;
107 }
108 if ( defined( $v = delete $parms{'-allowcontinue'} ) )
109 {
110 $self->{allowcontinue} = $v ? 1 : 0;
111 }
112 if ( defined( $v = delete $parms{'-allowempty'} ) )
113 {
114 $self->{allowempty} = $v ? 1 : 0;
115 }
116 if ( defined( $v = delete $parms{'-negativedeltas'} ) )
117 {
118 $self->{negativedeltas} = $v ? 1 : 0;
119 }
120 if ( defined( $v = delete $parms{'-commentchar'} ) )
121 {
122 if ( !defined $v || length($v) != 1 )
123 {
124 carp "Comment character must be unique.";
125 $errs++;
126 }
127 elsif ( $v =~ /[\[\]=\w]/ )
128 {
129 # must not be square bracket, equal sign or alphanumeric
130 carp "Illegal comment character.";
131 $errs++;
132 }
133 else
134 {
135 $self->{comment_char} = $v;
136 }
137 }
138 if ( defined( $v = delete $parms{'-allowedcommentchars'} ) )
139 {
140 # must not be square bracket, equal sign or alphanumeric
141 if ( !defined $v || $v =~ /[\[\]=\w]/ )
142 {
143 carp "Illegal value for -allowedcommentchars.";
144 $errs++;
145 }
146 else
147 {
148 $self->{allowed_comment_char} = $v;
149 }
150 }
151
152 if ( defined( $v = delete $parms{'-handle_trailing_comment'} ) )
153 {
154 $self->{handle_trailing_comment} = $v ? 1 : 0;
155 }
156 if ( defined( $v = delete $parms{'-php_compat'} ) )
157 {
158 $self->{php_compat} = $v ? 1 : 0;
159 }
160
161 $self->{comment_char} = '#' unless exists $self->{comment_char};
162 $self->{allowed_comment_char} = ';'
163 unless exists $self->{allowed_comment_char};
164
165 # make sure that comment character is always allowed
166 $self->{allowed_comment_char} .= $self->{comment_char};
167
168 $self->{_comments_at_end_of_file} = [];
169
170 # Any other parameters are unknown
171 while ( ( $k, $v ) = each %parms )
172 {
173 carp "Unknown named parameter $k=>$v";
174 $errs++;
175 }
176
177 return undef if $errs;
178
179 if ( $self->ReadConfig )
180 {
181 return $self;
182 }
183 else
184 {
185 return undef;
186 }
187 }
188
189
190 sub _caseify
191 {
192 my ( $self, @refs ) = @_;
193
194 if ( $self->_nocase )
195 {
196 foreach my $ref ( grep { defined } @refs[ 0 .. 1 ] )
197 {
198 ${$ref} = lc( ${$ref} );
199 }
200 }
201
202 if ( $self->{php_compat} )
203 {
204 foreach my $ref ( grep { defined } @refs[ 1 .. 1 ] )
205 {
206 ${$ref} =~ s{\[\]$}{};
207 }
208 foreach my $ref ( grep { defined } @refs[ 2 .. $#refs ] )
209 {
210 if ( length( ${$ref} ) >= 2 )
211 {
212 my $quote = substr( ${$ref}, 0, 1 );
213 if ( ( $quote eq q{"} or $quote eq q{'} )
214 and substr( ${$ref}, -1, 1 ) eq $quote )
215 {
216 ${$ref} = substr( ${$ref}, 1, -1 );
217 ${$ref} =~ s{$quote$quote}{}g;
218 ${$ref} =~ s{\\$quote}{$quote}g if $quote eq q{"};
219 }
220 }
221 }
222 }
223
224 return;
225 }
226
227 sub val
228 {
229 my ( $self, $sect, $parm, $def ) = @_;
230
231 # Always return undef on bad parameters
232 if ( not( defined($sect) && defined($parm) ) )
233 {
234 return;
235 }
236
237 $self->_caseify( \$sect, \$parm );
238
239 my $val_sect =
240 defined( $self->{v}{$sect}{$parm} )
241 ? $sect
242 : $self->{default};
243
244 my $val = $self->{v}{$val_sect}{$parm};
245
246 # If the value is undef, make it $def instead (which could just be undef)
247 if ( !defined($val) )
248 {
249 $val = $def;
250 }
251
252 # Return the value in the desired context
253 if (wantarray)
254 {
255 if ( ref($val) eq "ARRAY" )
256 {
257 return @$val;
258 }
259 elsif ( defined($val) )
260 {
261 return $val;
262 }
263 else
264 {
265 return;
266 }
267 }
268 elsif ( ref($val) eq "ARRAY" )
269 {
270 return join( ( defined($/) ? $/ : "\n" ), @$val );
271 }
272 else
273 {
274 return $val;
275 }
276 }
277
278
279 sub exists
280 {
281 my ( $self, $sect, $parm ) = @_;
282
283 $self->_caseify( \$sect, \$parm );
284
285 return ( exists $self->{v}{$sect}{$parm} );
286 }
287
288
289 sub push
290 {
291 my ( $self, $sect, $parm, @vals ) = @_;
292
293 return undef if not defined $sect;
294 return undef if not defined $parm;
295
296 $self->_caseify( \$sect, \$parm );
297
298 return undef if ( !defined( $self->{v}{$sect}{$parm} ) );
299
300 return 1 if ( !@vals );
301
302 $self->_touch_parameter( $sect, $parm );
303
304 $self->{EOT}{$sect}{$parm} = 'EOT'
305 if ( !defined $self->{EOT}{$sect}{$parm} );
306
307 $self->{v}{$sect}{$parm} = [ $self->{v}{$sect}{$parm} ]
308 unless ( ref( $self->{v}{$sect}{$parm} ) eq "ARRAY" );
309
310 CORE::push @{ $self->{v}{$sect}{$parm} }, @vals;
311 return 1;
312 }
313
314
315 sub setval
316 {
317 my $self = shift;
318 my $sect = shift;
319 my $parm = shift;
320 my @val = @_;
321
322 return undef if not defined $sect;
323 return undef if not defined $parm;
324
325 $self->_caseify( \$sect, \$parm );
326
327 if ( defined( $self->{v}{$sect}{$parm} ) )
328 {
329 $self->_touch_parameter( $sect, $parm );
330 if ( @val > 1 )
331 {
332 $self->{v}{$sect}{$parm} = \@val;
333 $self->{EOT}{$sect}{$parm} = 'EOT';
334 }
335 else
336 {
337 $self->{v}{$sect}{$parm} = shift @val;
338 }
339 return 1;
340 }
341 else
342 {
343 return undef;
344 }
345 }
346
347
348 sub newval
349 {
350 my $self = shift;
351 my $sect = shift;
352 my $parm = shift;
353 my @val = @_;
354
355 return undef if not defined $sect;
356 return undef if not defined $parm;
357
358 $self->_caseify( \$sect, \$parm );
359
360 $self->AddSection($sect);
361
362 if ( none { $_ eq $parm } @{ $self->{parms}{$sect} } )
363 {
364 CORE::push( @{ $self->{parms}{$sect} }, $parm );
365 }
366
367 $self->_touch_parameter( $sect, $parm );
368 if ( @val > 1 )
369 {
370 $self->{v}{$sect}{$parm} = \@val;
371 if ( !defined $self->{EOT}{$sect}{$parm} )
372 {
373 $self->{EOT}{$sect}{$parm} = 'EOT';
374 }
375 }
376 else
377 {
378 $self->{v}{$sect}{$parm} = shift @val;
379 }
380 return 1;
381 }
382
383
384 sub delval
385 {
386 my $self = shift;
387 my $sect = shift;
388 my $parm = shift;
389
390 return undef if not defined $sect;
391 return undef if not defined $parm;
392
393 $self->_caseify( \$sect, \$parm );
394
395 $self->{parms}{$sect} = [ grep { $_ ne $parm } @{ $self->{parms}{$sect} } ];
396 $self->_touch_parameter( $sect, $parm );
397 delete $self->{v}{$sect}{$parm};
398
399 return 1;
400 }
401
402
403 # Auxiliary function to make deep (aliasing-free) copies of data
404 # structures. Ignores blessed objects in tree (could be taught not
405 # to, if needed)
406 sub _deepcopy
407 {
408 my $ref = shift;
409
410 if ( !ref($ref) )
411 {
412 return $ref;
413 }
414
415 if ( UNIVERSAL::isa( $ref, "ARRAY" ) )
416 {
417 return [ map { _deepcopy($_) } @$ref ];
418 }
419
420 if ( UNIVERSAL::isa( $ref, "HASH" ) )
421 {
422 my $return = {};
423 foreach my $k ( keys %$ref )
424 {
425 $return->{$k} = _deepcopy( $ref->{$k} );
426 }
427 return $return;
428 }
429
430 carp "Unhandled data structure in $ref, cannot _deepcopy()";
431 }
432
433 # Internal method, gets the next line, taking proper care of line endings.
434 sub _nextline
435 {
436 my ( $self, $fh ) = @_;
437 my $s = '';
438 if ( !exists $self->{line_ends} )
439 {
440 # no $self->{line_ends} is a hint set by caller that we are at
441 # the first line (kludge kludge).
442 {
443 local $/ = \1;
444 my $nextchar;
445 do
446 {
447 $nextchar = <$fh>;
448 return undef if ( !defined $nextchar );
449 $s .= $nextchar;
450 } until ( $s =~ m/((\015|\012|\025|\n)$)/s );
451 $self->{line_ends} = $1;
452 if ( $nextchar eq "\x0d" )
453 {
454 # peek at the next char
455 $nextchar = <$fh>;
456 if ( $nextchar eq "\x0a" )
457 {
458 $self->{line_ends} .= "\x0a";
459 }
460 else
461 {
462 seek $fh, -1, SEEK_CUR();
463 }
464 }
465 }
466
467 # If there's a UTF BOM (Byte-Order-Mark) in the first
468 # character of the first line then remove it before processing
469 # ( http://www.unicode.org/unicode/faq/utf_bom.html#22 )
470 $s =~ s/\A//;
471
472 return $s;
473 }
474 else
475 {
476 local $/ = $self->{line_ends};
477 return scalar <$fh>;
478 }
479 }
480
481 # Internal method, closes or resets the file handle. To be called
482 # whenever ReadConfig() returns.
483 sub _rollback
484 {
485 my ( $self, $fh ) = @_;
486
487 # Only close if this is a filename, if it's
488 # an open handle, then just roll back to the start
489 if ( !ref( $self->{cf} ) )
490 {
491 close($fh) or Carp::confess("close failed: $!");
492 }
493 else
494 {
495 # Attempt to rollback to beginning, no problem if this fails (e.g. STDIN)
496 seek( $fh, 0, SEEK_SET() );
497 } # end if
498 }
499
500 sub _no_filename
501 {
502 my $self = shift;
503
504 my $fn = $self->{cf};
505
506 return ( not( defined($fn) && length($fn) ) );
507 }
508
509 sub _read_line_num
510 {
511 my $self = shift;
512
513 if (@_)
514 {
515 $self->{_read_line_num} = shift;
516 }
517
518 return $self->{_read_line_num};
519 }
520
521 # Reads the next line and removes the end of line from it.
522 sub _read_next_line
523 {
524 my ( $self, $fh ) = @_;
525
526 my $line = $self->_nextline($fh);
527
528 if ( !defined($line) )
529 {
530 return undef;
531 }
532
533 $self->_read_line_num( $self->_read_line_num() + 1 );
534
535 # Remove line ending char(s)
536 $line =~ s/(\015\012?|\012|\025|\n)\z//;
537
538 return $line;
539 }
540
541 sub _add_error
542 {
543 my ( $self, $msg ) = @_;
544
545 CORE::push( @Config::IniFiles::errors, $msg );
546
547 return;
548 }
549
550 # The current section - used for parsing.
551 sub _curr_sect
552 {
553 my $self = shift;
554
555 if (@_)
556 {
557 $self->{_curr_sect} = shift;
558 }
559
560 return $self->{_curr_sect};
561 }
562
563 # The current parameter - used for parsing.
564 sub _curr_parm
565 {
566 my $self = shift;
567
568 if (@_)
569 {
570 $self->{_curr_parm} = shift;
571 }
572
573 return $self->{_curr_parm};
574 }
575
576 # Current location - section and parameter.
577 sub _curr_loc
578 {
579 my $self = shift;
580
581 return ( $self->_curr_sect, $self->_curr_parm );
582 }
583
584 # The current value - used in parsing.
585 sub _curr_val
586 {
587 my $self = shift;
588
589 if (@_)
590 {
591 $self->{_curr_val} = shift;
592 }
593
594 return $self->{_curr_val};
595 }
596
597 sub _curr_cmts
598 {
599 my $self = shift;
600
601 if (@_)
602 {
603 $self->{_curr_cmts} = shift;
604 }
605
606 return $self->{_curr_cmts};
607 }
608
609 sub _curr_end_comment
610 {
611 my $self = shift;
612
613 if (@_)
614 {
615 $self->{_curr_end_comment} = shift;
616 }
617
618 return $self->{_curr_end_comment};
619 }
620
621 my $RET_CONTINUE = 1;
622 my $RET_BREAK;
623
624 sub _ReadConfig_handle_comment
625 {
626 my ( $self, $line ) = @_;
627
628 if ( $self->{negativedeltas}
629 and my ($to_delete) =
630 $line =~ m/\A$self->{comment_char} (.*) is deleted\z/ )
631 {
632 if ( my ($sect) = $to_delete =~ m/\A\[(.*)\]\z/ )
633 {
634 $self->DeleteSection($sect);
635 }
636 else
637 {
638 $self->delval( $self->_curr_sect, $to_delete );
639 }
640 }
641 else
642 {
643 CORE::push( @{ $self->_curr_cmts }, $line );
644 }
645
646 return $RET_CONTINUE;
647 }
648
649 sub _ReadConfig_new_section
650 {
651 my ( $self, $sect ) = @_;
652
653 $self->_caseify( undef, \$sect );
654
655 $self->_curr_sect($sect);
656 $self->AddSection( $self->_curr_sect );
657 $self->SetSectionComment( $self->_curr_sect, @{ $self->_curr_cmts } );
658 $self->_curr_cmts( [] );
659
660 return $RET_CONTINUE;
661 }
662
663 sub _handle_fallback_sect
664 {
665 my ($self) = @_;
666
667 if ( ( !defined( $self->_curr_sect ) ) and defined( $self->{fallback} ) )
668 {
669 $self->_curr_sect( $self->{fallback} );
670 $self->{fallback_used}++;
671 }
672
673 return;
674 }
675
676 sub _ReadConfig_load_value
677 {
678 my ( $self, $val_aref ) = @_;
679
680 # Now load value
681 if ( exists $self->{v}{ $self->_curr_sect }{ $self->_curr_parm }
682 && exists $self->{myparms}{ $self->_curr_sect }
683 && $self->_is_parm_in_sect( $self->_curr_loc ) )
684 {
685 $self->push( $self->_curr_loc, @$val_aref );
686 }
687 else
688 {
689 # Loaded parameters shadow imported ones, instead of appending
690 # to them
691 $self->newval( $self->_curr_loc, @$val_aref );
692 }
693
694 return;
695 }
696
697 sub _test_for_fallback_or_no_sect
698 {
699 my ( $self, $fh ) = @_;
700
701 $self->_handle_fallback_sect;
702
703 if ( !defined $self->_curr_sect )
704 {
705 $self->_add_error(
706 sprintf( '%d: %s',
707 $self->_read_line_num(),
708 qq#parameter found outside a section# )
709 );
710 $self->_rollback($fh);
711 return $RET_BREAK;
712 }
713
714 return $RET_CONTINUE;
715 }
716
717 sub _ReadConfig_handle_here_doc_param
718 {
719 my ( $self, $fh, $eotmark, $val_aref ) = @_;
720
721 my $foundeot = 0;
722 my $startline = $self->_read_line_num();
723
724 HERE_DOC_LOOP:
725 while ( defined( my $line = $self->_read_next_line($fh) ) )
726 {
727 if ( $line eq $eotmark )
728 {
729 $foundeot = 1;
730 last HERE_DOC_LOOP;
731 }
732 else
733 {
734 # Untaint
735 my ($contents) = $line =~ /(.*)/ms;
736 CORE::push( @$val_aref, $contents );
737 }
738 }
739
740 if ( !$foundeot )
741 {
742 $self->_add_error(
743 sprintf( '%d: %s',
744 $startline, qq#no end marker ("$eotmark") found# )
745 );
746 $self->_rollback($fh);
747 return $RET_BREAK;
748 }
749
750 return $RET_CONTINUE;
751 }
752
753 sub _ReadConfig_handle_non_here_doc_param
754 {
755 my ( $self, $fh, $val_aref ) = @_;
756
757 my $allCmt = $self->{allowed_comment_char};
758 my $end_commenthandle = $self->{handle_trailing_comment};
759
760 # process continuation lines, if any
761 $self->_process_continue_val($fh);
762
763 # we should split value and comments if there is any comment
764 if ( $end_commenthandle
765 and my ( $value_to_assign, $end_comment_to_assign ) =
766 $self->_curr_val =~ /(.*?)\s*[$allCmt]\s*(.*)$/ )
767 {
768 $self->_curr_val($value_to_assign);
769 $self->_curr_end_comment($end_comment_to_assign);
770 }
771 else
772 {
773 $self->_curr_end_comment(q{});
774 }
775
776 @{$val_aref} = ( $self->_curr_val );
777
778 return;
779 }
780
781 sub _ReadConfig_populate_values
782 {
783 my ( $self, $val_aref, $eotmark ) = @_;
784
785 $self->_ReadConfig_load_value($val_aref);
786
787 $self->SetParameterComment( $self->_curr_loc, @{ $self->_curr_cmts } );
788 $self->_curr_cmts( [] );
789 if ( defined $eotmark )
790 {
791 $self->SetParameterEOT( $self->_curr_loc, $eotmark );
792 }
793
794 # if handle_trailing_comment is off, this line makes no sense, since all $end_comment=""
795 $self->SetParameterTrailingComment( $self->_curr_loc,
796 $self->_curr_end_comment );
797
798 return;
799 }
800
801 sub _ReadConfig_param_assignment
802 {
803 my ( $self, $fh, $line, $parm, $value_to_assign ) = @_;
804
805 $self->_caseify( undef, \$parm, \$value_to_assign );
806
807 $self->_curr_val($value_to_assign);
808 $self->_curr_end_comment( undef() );
809
810 if ( !defined( $self->_test_for_fallback_or_no_sect($fh) ) )
811 {
812
813 return $RET_BREAK;
814 }
815
816 $self->_curr_parm($parm);
817
818 my @val = ();
819 my $eotmark;
820
821 if ( ($eotmark) = $self->_curr_val =~ /\A<<(.*)$/ )
822 {
823 if (
824 !defined(
825 $self->_ReadConfig_handle_here_doc_param(
826 $fh, $eotmark, \@val
827 )
828 )
829 )
830 {
831 return $RET_BREAK;
832 }
833 }
834 else
835 {
836 $self->_ReadConfig_handle_non_here_doc_param( $fh, \@val );
837 }
838
839 $self->_ReadConfig_populate_values( \@val, $eotmark );
840
841 return $RET_CONTINUE;
842 }
843
844 # Return 1 to continue - undef to terminate the loop.
845 sub _ReadConfig_handle_line
846 {
847 my ( $self, $fh, $line ) = @_;
848
849 my $allCmt = $self->{allowed_comment_char};
850
851 # ignore blank lines
852 if ( $line =~ /\A\s*\z/ )
853 {
854 return $RET_CONTINUE;
855 }
856
857 # collect comments
858 if ( $line =~ /\A\s*[$allCmt]/ )
859 {
860 return $self->_ReadConfig_handle_comment($line);
861 }
862
863 # New Section
864 if ( my ($sect) = $line =~ /\A\s*\[\s*(\S|\S.*\S)\s*\]\s*\z/ )
865 {
866 return $self->_ReadConfig_new_section($sect);
867 }
868
869 # New parameter
870 if ( my ( $parm, $value_to_assign ) =
871 $line =~ /^\s*([^=]*?[^=\s])\s*=\s*(.*)$/ )
872 {
873 return $self->_ReadConfig_param_assignment( $fh, $line, $parm,
874 $value_to_assign );
875 }
876
877 $self->_add_error(
878 sprintf(
879 "Line %d in file %s is malformed:\n\t\%s",
880 $self->_read_line_num(),
881 $self->GetFileName(), $line
882 )
883 );
884
885 return $RET_CONTINUE;
886 }
887
888 sub _ReadConfig_lines_loop
889 {
890 my ( $self, $fh ) = @_;
891
892 $self->_curr_sect( undef() );
893 $self->_curr_parm( undef() );
894 $self->_curr_val( undef() );
895 $self->_curr_cmts( [] );
896
897 while ( defined( my $line = $self->_read_next_line($fh) ) )
898 {
899 if (
900 !defined( scalar( $self->_ReadConfig_handle_line( $fh, $line ) ) ) )
901 {
902 return undef;
903 }
904 }
905
906 return 1;
907 }
908
909 sub ReadConfig
910 {
911 my $self = shift;
912
913 @Config::IniFiles::errors = ();
914
915 # Initialize (and clear out) storage hashes
916 $self->{sects} = [];
917 $self->{parms} = {};
918 $self->{group} = {};
919 $self->{v} = {};
920 $self->{sCMT} = {};
921 $self->{pCMT} = {};
922 $self->{EOT} = {};
923 $self->{mysects} =
924 []; # A pair of hashes to remember which params are loaded
925 $self->{myparms} = {}; # or set using the API vs. imported - useful for
926 $self->{peCMT} =
927 {}; # this will store trailing comments at the end of single-line params
928 $self->{e} = {}; # If a section already exists
929 $self->{mye} = {}; # If a section already exists
930 # import shadowing, see below, and WriteConfig($fn, -delta=>1)
931
932 if ( defined $self->{imported} )
933 {
934 foreach my $field (qw(sects parms group v sCMT pCMT EOT e))
935 {
936 $self->{$field} = _deepcopy( $self->{imported}->{$field} );
937 }
938 }
939
940 if ( $self->_no_filename )
941 {
942 return 1;
943 }
944
945 # If we want warnings, then send one to the STDERR log
946 if ( $self->{reloadwarn} )
947 {
948 my ( $ss, $mm, $hh, $DD, $MM, $YY ) = ( localtime(time) )[ 0 .. 5 ];
949 printf STDERR
950 "PID %d reloading config file %s at %d.%02d.%02d %02d:%02d:%02d\n",
951 $$, $self->{cf}, $YY + 1900, $MM + 1, $DD, $hh, $mm, $ss;
952 }
953
954 # Get a filehandle, allowing almost any type of 'file' parameter
955 my $fh = $self->_make_filehandle( $self->{cf} );
956 if ( !$fh )
957 {
958 carp "Failed to open $self->{cf}: $!";
959 return undef;
960 }
961
962 # Get mod time of file so we can retain it (if not from STDIN)
963 # also check if it's a real file (could have been a filehandle made from a scalar).
964 if ( ref($fh) ne "IO::Scalar" && -e $fh )
965 {
966 if ( not exists $self->{file_mode} )
967 {
968 my @stats = stat $fh;
969 $self->{file_mode} = sprintf( "%04o", $stats[2] )
970 if defined $stats[2];
971 }
972 }
973
974 # The first lines of the file must be blank, comments or start with [
975 my $first = '';
976
977 delete $self->{line_ends}; # Marks start of parsing for _nextline()
978
979 $self->_read_line_num(0);
980
981 if ( !defined( $self->_ReadConfig_lines_loop($fh) ) )
982 {
983 return undef;
984 }
985
986 # Special case: return undef if file is empty. (suppress this line to
987 # restore the more intuitive behaviour of accepting empty files)
988 if ( !keys %{ $self->{v} } && !$self->{allowempty} )
989 {
990 $self->_add_error("Empty file treated as error");
991 $self->_rollback($fh);
992 return undef;
993 }
994
995 if ( defined( my $defaultsect = $self->{startup_settings}->{-default} ) )
996 {
997 $self->AddSection($defaultsect);
998 }
999
1000 $self->_SetEndComments( @{ $self->_curr_cmts } );
1001
1002 $self->_rollback($fh);
1003 return ( @Config::IniFiles::errors ? undef : 1 );
1004 }
1005
1006
1007 sub Sections
1008 {
1009 my $self = shift;
1010
1011 return @{ _aref_or_empty( $self->{sects} ) };
1012 }
1013
1014
1015 sub SectionExists
1016 {
1017 my $self = shift;
1018 my $sect = shift;
1019
1020 return undef if not defined $sect;
1021
1022 $self->_caseify( \$sect );
1023
1024 return ( ( exists $self->{e}{$sect} ) ? 1 : 0 );
1025 }
1026
1027
1028 sub _AddSection_Helper
1029 {
1030 my ( $self, $sect ) = @_;
1031 $self->{e}{$sect} = 1;
1032 CORE::push @{ $self->{sects} }, $sect;
1033 $self->_touch_section($sect);
1034
1035 $self->SetGroupMember($sect);
1036
1037 # Set up the parameter names and values lists
1038 $self->{parms}{$sect} ||= [];
1039
1040 if ( !defined( $self->{v}{$sect} ) )
1041 {
1042 $self->{sCMT}{$sect} = [];
1043 $self->{pCMT}{$sect} = {}; # Comments above parameters
1044 $self->{parms}{$sect} = [];
1045 $self->{v}{$sect} = {};
1046 }
1047
1048 return;
1049 }
1050
1051 sub AddSection
1052 {
1053 my ( $self, $sect ) = @_;
1054
1055 return undef if not defined $sect;
1056
1057 $self->_caseify( \$sect );
1058
1059 if ( $self->SectionExists($sect) )
1060 {
1061 return;
1062 }
1063
1064 return $self->_AddSection_Helper($sect);
1065 }
1066
1067 # Marks a section as modified by us (this includes deleted by us).
1068 sub _touch_section
1069 {
1070 my ( $self, $sect ) = @_;
1071
1072 $self->{mysects} ||= [];
1073
1074 unless ( exists $self->{mye}{$sect} )
1075 {
1076 CORE::push @{ $self->{mysects} }, $sect;
1077 $self->{mye}{$sect} = 1;
1078 }
1079
1080 return;
1081 }
1082
1083 # Marks a parameter as modified by us (this includes deleted by us).
1084 sub _touch_parameter
1085 {
1086 my ( $self, $sect, $parm ) = @_;
1087
1088 $self->_touch_section($sect);
1089 return if ( !exists $self->{v}{$sect} );
1090 $self->{myparms}{$sect} ||= [];
1091
1092 if ( !$self->_is_parm_in_sect( $sect, $parm ) )
1093 {
1094 CORE::push @{ $self->{myparms}{$sect} }, $parm;
1095 }
1096
1097 return;
1098 }
1099
1100
1101 sub DeleteSection
1102 {
1103 my $self = shift;
1104 my $sect = shift;
1105
1106 return undef if not defined $sect;
1107
1108 $self->_caseify( \$sect );
1109
1110 # This is done the fast way, change if data structure changes!!
1111 delete $self->{v}{$sect};
1112 delete $self->{sCMT}{$sect};
1113 delete $self->{pCMT}{$sect};
1114 delete $self->{EOT}{$sect};
1115 delete $self->{parms}{$sect};
1116 delete $self->{myparms}{$sect};
1117 delete $self->{e}{$sect};
1118
1119 $self->{sects} = [ grep { $_ ne $sect } @{ $self->{sects} } ];
1120 $self->_touch_section($sect);
1121
1122 $self->RemoveGroupMember($sect);
1123
1124 return 1;
1125 } # end DeleteSection
1126
1127
1128 sub RenameSection
1129 {
1130 my $self = shift;
1131 my $old_sect = shift;
1132 my $new_sect = shift;
1133 my $include_groupmembers = shift;
1134 return undef
1135 unless $self->CopySection( $old_sect, $new_sect,
1136 $include_groupmembers );
1137 return $self->DeleteSection($old_sect);
1138
1139 } # end RenameSection
1140
1141
1142 sub CopySection
1143 {
1144 my $self = shift;
1145 my $old_sect = shift;
1146 my $new_sect = shift;
1147 my $include_groupmembers = shift;
1148
1149 if ( not defined $old_sect
1150 or not defined $new_sect
1151 or !$self->SectionExists($old_sect)
1152 or $self->SectionExists($new_sect) )
1153 {
1154 return undef;
1155 }
1156
1157 $self->_caseify( \$new_sect );
1158 $self->_AddSection_Helper($new_sect);
1159
1160 # This is done the fast way, change if data structure changes!!
1161 foreach my $key (qw(v sCMT pCMT EOT parms myparms e))
1162 {
1163 next unless exists $self->{$key}{$old_sect};
1164 $self->{$key}{$new_sect} =
1165 Config::IniFiles::_deepcopy( $self->{$key}{$old_sect} );
1166 }
1167
1168 if ($include_groupmembers)
1169 {
1170 foreach my $old_groupmember ( $self->GroupMembers($old_sect) )
1171 {
1172 my $new_groupmember = $old_groupmember;
1173 $new_groupmember =~ s/\A\Q$old_sect\E/$new_sect/;
1174 $self->CopySection( $old_groupmember, $new_groupmember );
1175 }
1176 }
1177
1178 return 1;
1179 } # end CopySection
1180
1181
1182 sub _aref_or_empty
1183 {
1184 my ($aref) = @_;
1185
1186 return ( ( defined($aref) and ref($aref) eq 'ARRAY' ) ? $aref : [] );
1187 }
1188
1189 sub Parameters
1190 {
1191 my $self = shift;
1192 my $sect = shift;
1193
1194 return undef if not defined $sect;
1195
1196 $self->_caseify( \$sect );
1197
1198 return @{ _aref_or_empty( $self->{parms}{$sect} ) };
1199 }
1200
1201
1202 sub Groups
1203 {
1204 my $self = shift;
1205
1206 if ( ref( $self->{group} ) eq 'HASH' )
1207 {
1208 return keys %{ $self->{group} };
1209 }
1210 else
1211 {
1212 return ();
1213 }
1214 }
1215
1216
1217 sub _group_member_handling_skeleton
1218 {
1219 my ( $self, $sect, $method ) = @_;
1220
1221 return undef if not defined $sect;
1222
1223 if ( !( my ($group) = ( $sect =~ /\A(\S+)\s+\S/ ) ) )
1224 {
1225 return 1;
1226 }
1227 else
1228 {
1229 return $self->$method( $sect, $group );
1230 }
1231 }
1232
1233 sub _SetGroupMember_helper
1234 {
1235 my ( $self, $sect, $group ) = @_;
1236
1237 if ( not exists( $self->{group}{$group} ) )
1238 {
1239 $self->{group}{$group} = [];
1240 }
1241
1242 if ( none { $_ eq $sect } @{ $self->{group}{$group} } )
1243 {
1244 CORE::push @{ $self->{group}{$group} }, $sect;
1245 }
1246
1247 return;
1248 }
1249
1250 sub SetGroupMember
1251 {
1252 my ( $self, $sect ) = @_;
1253
1254 return $self->_group_member_handling_skeleton( $sect,
1255 '_SetGroupMember_helper' );
1256 }
1257
1258
1259 sub _RemoveGroupMember_helper
1260 {
1261 my ( $self, $sect, $group ) = @_;
1262
1263 if ( !exists $self->{group}{$group} )
1264 {
1265 return;
1266 }
1267
1268 $self->{group}{$group} =
1269 [ grep { $_ ne $sect } @{ $self->{group}{$group} } ];
1270
1271 return;
1272 }
1273
1274 sub RemoveGroupMember
1275 {
1276 my ( $self, $sect ) = @_;
1277
1278 return $self->_group_member_handling_skeleton( $sect,
1279 '_RemoveGroupMember_helper' );
1280 }
1281
1282
1283 sub GroupMembers
1284 {
1285 my ( $self, $group ) = @_;
1286
1287 return undef if not defined $group;
1288
1289 $self->_caseify( \$group );
1290
1291 return @{ _aref_or_empty( $self->{group}{$group} ) };
1292 }
1293
1294
1295 sub SetWriteMode
1296 {
1297 my ( $self, $mode ) = @_;
1298
1299 if ( not( defined($mode) && ( $mode =~ m/[0-7]{3}/ ) ) )
1300 {
1301 return undef;
1302 }
1303
1304 return ( $self->{file_mode} = $mode );
1305 }
1306
1307
1308 sub GetWriteMode
1309 {
1310 my $self = shift;
1311
1312 return $self->{file_mode};
1313 }
1314
1315
1316 sub _write_config_to_filename
1317 {
1318 my ( $self, $filename, %parms ) = @_;
1319
1320 if ( -e $filename )
1321 {
1322 if ( not( -w $filename ) )
1323 {
1324 #carp "File $filename is not writable. Refusing to write config";
1325 return undef;
1326 }
1327 if ( not exists $self->{file_mode} )
1328 {
1329 my $mode = ( stat $filename )[2];
1330 $self->{file_mode} = sprintf "%04o", ( $mode & 0777 );
1331 }
1332
1333 #carp "Using mode $self->{file_mode} for file $file";
1334 }
1335
1336 my ( $fh, $new_file );
1337
1338 # We need to trap the exception that tempfile() may throw and instead
1339 # carp() and return undef() because that was the previous behaviour:
1340 #
1341 # See RT #77039 ( https://rt.cpan.org/Ticket/Display.html?id=77039 )
1342 eval {
1343 ( $fh, $new_file ) =
1344 tempfile( "temp.ini-XXXXXXXXXX", DIR => dirname($filename) );
1345
1346 # Convert the filehandle to a "text" filehandle suitable for use
1347 # on Windows (and other platforms).
1348 #
1349 # This may break compatibility for ultra-old perls (ones before 5.6.0)
1350 # so I say - Good Riddance!
1351 if ( $^O =~ m/\AMSWin/ )
1352 {
1353 binmode $fh, ':crlf';
1354 }
1355 };
1356
1357 if ($@)
1358 {
1359 carp("Unable to write temp config file: $!");
1360 return undef;
1361 }
1362
1363 $self->OutputConfigToFileHandle( $fh, $parms{-delta} );
1364 close($fh) or Carp::confess("close failed: $!");
1365 if ( !rename( $new_file, $filename ) )
1366 {
1367 carp "Unable to rename temp config file ($new_file) to ${filename}: $!";
1368 return undef;
1369 }
1370 if ( exists $self->{file_mode} )
1371 {
1372 if ( not chmod( oct( $self->{file_mode} ), $filename ) )
1373 {
1374 carp "Unable to chmod $filename!";
1375 }
1376 }
1377
1378 return 1;
1379 }
1380
1381 sub _write_config_with_a_made_fh
1382 {
1383 my ( $self, $fh, %parms ) = @_;
1384
1385 # Only roll back if it's not STDIN (if it is, Carp)
1386 if ( $fh == \*STDIN )
1387 {
1388 carp "Cannot write configuration file to STDIN.";
1389 }
1390 else
1391 {
1392 seek( $fh, 0, SEEK_SET() );
1393
1394 # Make sure to keep the previous junk out.
1395 # See:
1396 # https://rt.cpan.org/Public/Bug/Display.html?id=103496
1397 truncate( $fh, 0 );
1398 $self->OutputConfigToFileHandle( $fh, $parms{-delta} );
1399 seek( $fh, 0, SEEK_SET() );
1400 } # end if
1401
1402 return 1;
1403 }
1404
1405 sub _write_config_to_fh
1406 {
1407 my ( $self, $file, %parms ) = @_;
1408
1409 # Get a filehandle, allowing almost any type of 'file' parameter
1410 ## NB: If this were a filename, this would fail because _make_file
1411 ## opens a read-only handle, but we have already checked that case
1412 ## so re-using the logic is ok [JW/WADG]
1413 my $fh = $self->_make_filehandle($file);
1414
1415 if ( !$fh )
1416 {
1417 carp "Could not find a filehandle for the input stream ($file): $!";
1418 return undef;
1419 }
1420
1421 return $self->_write_config_with_a_made_fh( $fh, %parms );
1422 }
1423
1424 sub WriteConfig
1425 {
1426 my ( $self, $file, %parms ) = @_;
1427
1428 return undef unless defined $file;
1429
1430 # If we are using a filename, then do mode checks and write to a
1431 # temporary file to avoid a race condition
1432 if ( !ref($file) )
1433 {
1434 return $self->_write_config_to_filename( $file, %parms );
1435 }
1436
1437 # Otherwise, reset to the start of the file and write, unless we are using
1438 # STDIN
1439 else
1440 {
1441 return $self->_write_config_to_fh( $file, %parms );
1442 }
1443 }
1444
1445
1446 sub RewriteConfig
1447 {
1448 my $self = shift;
1449
1450 if ( $self->_no_filename )
1451 {
1452 return 1;
1453 }
1454
1455 return $self->WriteConfig( $self->{cf} );
1456 }
1457
1458
1459 sub GetFileName
1460 {
1461 my $self = shift;
1462
1463 return $self->{cf};
1464 }
1465
1466
1467 sub SetFileName
1468 {
1469 my ( $self, $new_filename ) = @_;
1470
1471 if ( length($new_filename) > 0 )
1472 {
1473 return ( $self->{cf} = $new_filename );
1474 }
1475 else
1476 {
1477 return undef;
1478 }
1479 }
1480
1481
1482 sub _calc_eot_mark
1483 {
1484 my ( $self, $sect, $parm, $val ) = @_;
1485
1486 my $eotmark = $self->{EOT}{$sect}{$parm} || 'EOT';
1487
1488 # Make sure the $eotmark does not occur inside the string.
1489 my @letters = ( 'A' .. 'Z' );
1490 my $joined_val = join( q{ }, @$val );
1491 while ( index( $joined_val, $eotmark ) >= 0 )
1492 {
1493 $eotmark .= $letters[ rand(@letters) ];
1494 }
1495
1496 return $eotmark;
1497 }
1498
1499 sub _OutputParam
1500 {
1501 my ( $self, $sect, $parm, $val, $end_comment, $output_cb ) = @_;
1502
1503 my $line_loop = sub {
1504 my ($mapper) = @_;
1505
1506 foreach my $line ( @{$val}[ 0 .. $#$val - 1 ] )
1507 {
1508 $output_cb->( $mapper->($line) );
1509 }
1510 $output_cb->(
1511 $mapper->( $val->[-1] ),
1512 ( $end_comment ? (" $self->{comment_char} $end_comment") : () ),
1513 );
1514 return;
1515 };
1516
1517 if ( !@$val )
1518 {
1519 # An empty variable - see:
1520 # https://rt.cpan.org/Public/Bug/Display.html?id=68554
1521 $output_cb->("$parm=");
1522 }
1523 elsif ( ( @$val == 1 ) or $self->{nomultiline} )
1524 {
1525 $line_loop->( sub { my ($line) = @_; return "$parm=$line"; } );
1526 }
1527 else
1528 {
1529 my $eotmark = $self->_calc_eot_mark( $sect, $parm, $val );
1530
1531 $output_cb->("$parm= <<$eotmark");
1532 $line_loop->( sub { my ($line) = @_; return $line; } );
1533 $output_cb->($eotmark);
1534 }
1535
1536 return;
1537 }
1538
1539 sub OutputConfig
1540 {
1541 my ( $self, $delta ) = @_;
1542
1543 return $self->OutputConfigToFileHandle( select(), $delta );
1544 }
1545
1546 sub _output_comments
1547 {
1548 my ( $self, $print_line, $comments_aref ) = @_;
1549
1550 if ( ref($comments_aref) eq 'ARRAY' )
1551 {
1552 foreach my $comment (@$comments_aref)
1553 {
1554 $print_line->($comment);
1555 }
1556 }
1557
1558 return;
1559 }
1560
1561 sub _process_continue_val
1562 {
1563 my ( $self, $fh ) = @_;
1564
1565 if ( not $self->{allowcontinue} )
1566 {
1567 return;
1568 }
1569
1570 my $val = $self->_curr_val;
1571
1572 while ( $val =~ s/\\\z// )
1573 {
1574 $val .= $self->_read_next_line($fh);
1575 }
1576
1577 $self->_curr_val($val);
1578
1579 return;
1580 }
1581
1582 sub _output_param_total
1583 {
1584 my ( $self, $sect, $parm, $print_line, $split_val, $delta ) = @_;
1585 if ( !defined $self->{v}{$sect}{$parm} )
1586 {
1587 if ($delta)
1588 {
1589 $print_line->("$self->{comment_char} $parm is deleted");
1590 }
1591 else
1592 {
1593 warn "Weird unknown parameter $parm" if $^W;
1594 }
1595 return;
1596 }
1597
1598 $self->_output_comments( $print_line, $self->{pCMT}{$sect}{$parm} );
1599
1600 my $val = $self->{v}{$sect}{$parm};
1601 my $end_comment = $self->{peCMT}{$sect}{$parm};
1602
1603 return if !defined($val); # No parameter exists !!
1604
1605 $self->_OutputParam( $sect, $parm, $split_val->($val),
1606 ( defined($end_comment) ? $end_comment : "" ), $print_line, );
1607
1608 return;
1609 }
1610
1611 sub _output_section
1612 {
1613 my ( $self, $sect, $print_line, $split_val, $delta, $position ) = @_;
1614
1615 if ( !defined $self->{v}{$sect} )
1616 {
1617 if ($delta)
1618 {
1619 $print_line->("$self->{comment_char} [$sect] is deleted");
1620 }
1621 else
1622 {
1623 warn "Weird unknown section $sect" if $^W;
1624 }
1625 return;
1626 }
1627 return if not defined $self->{v}{$sect};
1628 $print_line->() if ( $position > 0 );
1629 $self->_output_comments( $print_line, $self->{sCMT}{$sect} );
1630
1631 if ( !( $self->{fallback_used} and $sect eq $self->{fallback} ) )
1632 {
1633 $print_line->("[$sect]");
1634 }
1635 return if ref( $self->{v}{$sect} ) ne 'HASH';
1636
1637 foreach my $parm ( @{ $self->{ $delta ? "myparms" : "parms" }{$sect} } )
1638 {
1639 $self->_output_param_total( $sect, $parm, $print_line, $split_val,
1640 $delta );
1641 }
1642
1643 return;
1644 }
1645
1646 sub OutputConfigToFileHandle
1647 {
1648 # We need no strict 'refs' to be able to print to $fh if it points
1649 # to a glob filehandle.
1650 no strict 'refs';
1651 my ( $self, $fh, $delta ) = @_;
1652
1653 my $ors =
1654 $self->{line_ends}
1655 || $\
1656 || "\n"; # $\ is normally unset, but use input by default
1657 my $print_line = sub {
1658 print {$fh} ( @_, $ors )
1659 or die
1660 "Config-IniFiles cannot print to filehandle (out-of-space?). Aborting!";
1661 return;
1662 };
1663 my $split_val = sub {
1664 my ($val) = @_;
1665
1666 return (
1667 ( ref($val) eq 'ARRAY' )
1668 ? $val
1669 : [ split /[$ors]/, $val, -1 ]
1670 );
1671 };
1672
1673 my $position = 0;
1674
1675 foreach my $sect ( @{ $self->{ $delta ? "mysects" : "sects" } } )
1676 {
1677 $self->_output_section( $sect, $print_line, $split_val, $delta,
1678 $position++ );
1679 }
1680
1681 $self->_output_comments( $print_line, [ $self->_GetEndComments() ] );
1682
1683 return 1;
1684 }
1685
1686
1687 sub SetSectionComment
1688 {
1689 my ( $self, $sect, @comment ) = @_;
1690
1691 if ( not( defined($sect) && @comment ) )
1692 {
1693 return undef;
1694 }
1695
1696 $self->_caseify( \$sect );
1697
1698 $self->_touch_section($sect);
1699
1700 # At this point it's possible to have a comment for a section that
1701 # doesn't exist. This comment will not get written to the INI file.
1702 $self->{sCMT}{$sect} = $self->_markup_comments( \@comment );
1703
1704 return scalar @comment;
1705 }
1706
1707 # this helper makes sure that each line is preceded with the correct comment
1708 # character
1709 sub _markup_comments
1710 {
1711 my ( $self, $comment_aref ) = @_;
1712
1713 my $allCmt = $self->{allowed_comment_char};
1714 my $cmtChr = $self->{comment_char};
1715
1716 my $is_comment = qr/\A\s*[$allCmt]/;
1717
1718 # TODO : Maybe create a qr// out of it.
1719 return [ map { ( $_ =~ $is_comment ) ? $_ : "$cmtChr $_" } @$comment_aref ];
1720 }
1721
1722
1723 sub _return_comment
1724 {
1725 my ( $self, $comment_aref ) = @_;
1726
1727 my $delim = defined($/) ? $/ : "\n";
1728
1729 return wantarray() ? @$comment_aref : join( $delim, @$comment_aref );
1730 }
1731
1732 sub GetSectionComment
1733 {
1734 my ( $self, $sect ) = @_;
1735
1736 return undef if not defined $sect;
1737
1738 $self->_caseify( \$sect );
1739
1740 if ( !exists $self->{sCMT}{$sect} )
1741 {
1742 return undef;
1743 }
1744
1745 return $self->_return_comment( $self->{sCMT}{$sect} );
1746 }
1747
1748
1749 sub DeleteSectionComment
1750 {
1751 my $self = shift;
1752 my $sect = shift;
1753
1754 return undef if not defined $sect;
1755
1756 $self->_caseify( \$sect );
1757 $self->_touch_section($sect);
1758
1759 delete $self->{sCMT}{$sect};
1760
1761 return;
1762 }
1763
1764
1765 sub SetParameterComment
1766 {
1767 my ( $self, $sect, $parm, @comment ) = @_;
1768
1769 if ( not( defined($sect) && defined($parm) && @comment ) )
1770 {
1771 return undef;
1772 }
1773
1774 $self->_caseify( \$sect, \$parm );
1775
1776 $self->_touch_parameter( $sect, $parm );
1777
1778 # Note that at this point, it's possible to have a comment for a parameter,
1779 # without that parameter actually existing in the INI file.
1780 $self->{pCMT}{$sect}{$parm} = $self->_markup_comments( \@comment );
1781
1782 return scalar @comment;
1783 }
1784
1785 sub _SetEndComments
1786 {
1787 my $self = shift;
1788 my @comments = @_;
1789
1790 $self->{_comments_at_end_of_file} = \@comments;
1791
1792 return 1;
1793 }
1794
1795 sub _GetEndComments
1796 {
1797 my $self = shift;
1798
1799 return @{ $self->{_comments_at_end_of_file} };
1800 }
1801
1802
1803 sub GetParameterComment
1804 {
1805 my ( $self, $sect, $parm ) = @_;
1806
1807 if ( not( defined($sect) && defined($parm) ) )
1808 {
1809 return undef;
1810 }
1811
1812 $self->_caseify( \$sect, \$parm );
1813
1814 if (
1815 not( exists( $self->{pCMT}{$sect} )
1816 && exists( $self->{pCMT}{$sect}{$parm} ) )
1817 )
1818 {
1819 return undef;
1820 }
1821
1822 return $self->_return_comment( $self->{pCMT}{$sect}{$parm} );
1823 }
1824
1825
1826 sub DeleteParameterComment
1827 {
1828 my ( $self, $sect, $parm ) = @_;
1829
1830 if ( not( defined($sect) && defined($parm) ) )
1831 {
1832 return undef;
1833 }
1834
1835 $self->_caseify( \$sect, \$parm );
1836
1837 # If the parameter doesn't exist, our goal has already been achieved
1838 if ( exists( $self->{pCMT}{$sect} )
1839 && exists( $self->{pCMT}{$sect}{$parm} ) )
1840 {
1841 $self->_touch_parameter( $sect, $parm );
1842 delete $self->{pCMT}{$sect}{$parm};
1843 }
1844
1845 return 1;
1846 }
1847
1848
1849 sub GetParameterEOT
1850 {
1851 my ( $self, $sect, $parm ) = @_;
1852
1853 if ( not( defined($sect) && defined($parm) ) )
1854 {
1855 return undef;
1856 }
1857
1858 $self->_caseify( \$sect, \$parm );
1859
1860 return $self->{EOT}{$sect}{$parm};
1861 }
1862
1863
1864 sub SetParameterEOT
1865 {
1866 my ( $self, $sect, $parm, $EOT ) = @_;
1867
1868 if ( not( defined($sect) && defined($parm) && defined($EOT) ) )
1869 {
1870 return undef;
1871 }
1872
1873 $self->_caseify( \$sect, \$parm );
1874
1875 $self->_touch_parameter( $sect, $parm );
1876
1877 $self->{EOT}{$sect}{$parm} = $EOT;
1878
1879 return;
1880 }
1881
1882
1883 sub DeleteParameterEOT
1884 {
1885 my ( $self, $sect, $parm ) = @_;
1886
1887 if ( not( defined($sect) && defined($parm) ) )
1888 {
1889 return undef;
1890 }
1891
1892 $self->_caseify( \$sect, \$parm );
1893
1894 $self->_touch_parameter( $sect, $parm );
1895 delete $self->{EOT}{$sect}{$parm};
1896
1897 return;
1898 }
1899
1900
1901 sub SetParameterTrailingComment
1902 {
1903 my ( $self, $sect, $parm, $cmt ) = @_;
1904
1905 if ( not( defined($sect) && defined($parm) && defined($cmt) ) )
1906 {
1907 return undef;
1908 }
1909
1910 $self->_caseify( \$sect, \$parm );
1911
1912 # confirm the parameter exist
1913 return undef if not exists $self->{v}{$sect}{$parm};
1914
1915 $self->_touch_parameter( $sect, $parm );
1916 $self->{peCMT}{$sect}{$parm} = $cmt;
1917
1918 return 1;
1919 }
1920
1921
1922 sub GetParameterTrailingComment
1923 {
1924 my ( $self, $sect, $parm ) = @_;
1925
1926 if ( not( defined($sect) && defined($parm) ) )
1927 {
1928 return undef;
1929 }
1930
1931 $self->_caseify( \$sect, \$parm );
1932
1933 # confirm the parameter exist
1934 return undef if not exists $self->{v}{$sect}{$parm};
1935 return $self->{peCMT}{$sect}{$parm};
1936 }
1937
1938
1939 sub Delete
1940 {
1941 my $self = shift;
1942
1943 foreach my $section ( $self->Sections() )
1944 {
1945 $self->DeleteSection($section);
1946 }
1947
1948 return 1;
1949 } # end Delete
1950
1951
1952 ############################################################
1953 #
1954 # TIEHASH Methods
1955 #
1956 # Description:
1957 # These methods allow you to tie a hash to the
1958 # Config::IniFiles object. Note that, when tied, the
1959 # user wants to look at thinks like $ini{sec}{parm}, but the
1960 # TIEHASH only provides one level of hash interface, so the
1961 # root object gets asked for a $ini{sec}, which this
1962 # implements. To further tie the {parm} hash, the internal
1963 # class Config::IniFiles::_section, is provided, below.
1964 #
1965 ############################################################
1966 # ----------------------------------------------------------
1967 # Date Modification Author
1968 # ----------------------------------------------------------
1969 # 2000May09 Created method JW
1970 # ----------------------------------------------------------
1971 sub TIEHASH
1972 {
1973 my $class = shift;
1974 my %parms = @_;
1975
1976 # Get a new object
1977 my $self = $class->new(%parms);
1978
1979 return $self;
1980 } # end TIEHASH
1981
1982 # ----------------------------------------------------------
1983 # Date Modification Author
1984 # ----------------------------------------------------------
1985 # 2000May09 Created method JW
1986 # ----------------------------------------------------------
1987 sub FETCH
1988 {
1989 my $self = shift;
1990 my ($key) = @_;
1991
1992 $self->{_section_cache} ||= {};
1993
1994 $self->_caseify( \$key );
1995 return if ( !$self->{v}{$key} );
1996
1997 return $self->{_section_cache}->{$key}
1998 if exists $self->{_section_cache}->{$key};
1999
2000 my %retval;
2001 tie %retval, 'Config::IniFiles::_section', $self, $key;
2002 return $self->{_section_cache}->{$key} = \%retval;
2003
2004 } # end FETCH
2005
2006 # ----------------------------------------------------------
2007 # Date Modification Author
2008 # ----------------------------------------------------------
2009 # 2000Jun14 Fixed bug where wrong ref was saved JW
2010 # 2000Oct09 Fixed possible but in %parms with defaults JW
2011 # 2001Apr04 Fixed -nocase problem in storing JW
2012 # ----------------------------------------------------------
2013 sub STORE
2014 {
2015 my $self = shift;
2016 my ( $key, $ref ) = @_;
2017
2018 return undef unless ref($ref) eq 'HASH';
2019
2020 $self->_caseify( \$key );
2021
2022 $self->AddSection($key);
2023 $self->{v}{$key} = {%$ref};
2024 $self->{parms}{$key} = [ keys %$ref ];
2025 $self->{myparms}{$key} = [ keys %$ref ];
2026
2027 return 1;
2028 } # end STORE
2029
2030 # ----------------------------------------------------------
2031 # Date Modification Author
2032 # ----------------------------------------------------------
2033 # 2000May09 Created method JW
2034 # 2000Dec17 Now removes comments, groups and EOTs too JW
2035 # 2001Arp04 Fixed -nocase problem JW
2036 # ----------------------------------------------------------
2037 sub DELETE
2038 {
2039 my $self = shift;
2040 my ($key) = @_;
2041
2042 my $retval = $self->FETCH($key);
2043 $self->DeleteSection($key);
2044 return $retval;
2045 } # end DELETE
2046
2047 # ----------------------------------------------------------
2048 # Date Modification Author
2049 # ----------------------------------------------------------
2050 # 2000May09 Created method JW
2051 # ----------------------------------------------------------
2052 sub CLEAR
2053 {
2054 my $self = shift;
2055
2056 return $self->Delete();
2057 } # end CLEAR
2058
2059 # ----------------------------------------------------------
2060 # Date Modification Author
2061 # ----------------------------------------------------------
2062 # 2000May09 Created method JW
2063 # ----------------------------------------------------------
2064 sub FIRSTKEY
2065 {
2066 my $self = shift;
2067
2068 $self->{tied_enumerator} = 0;
2069 return $self->NEXTKEY();
2070 } # end FIRSTKEY
2071
2072 # ----------------------------------------------------------
2073 # Date Modification Author
2074 # ----------------------------------------------------------
2075 # 2000May09 Created method JW
2076 # ----------------------------------------------------------
2077 sub NEXTKEY
2078 {
2079 my $self = shift;
2080 my ($last) = @_;
2081
2082 my $i = $self->{tied_enumerator}++;
2083 my $key = $self->{sects}[$i];
2084 return if ( !defined $key );
2085 return wantarray ? ( $key, $self->FETCH($key) ) : $key;
2086 } # end NEXTKEY
2087
2088 # ----------------------------------------------------------
2089 # Date Modification Author
2090 # ----------------------------------------------------------
2091 # 2000May09 Created method JW
2092 # 2001Apr04 Fixed -nocase bug and false true bug JW
2093 # ----------------------------------------------------------
2094 sub EXISTS
2095 {
2096 my $self = shift;
2097 my ($key) = @_;
2098 return $self->SectionExists($key);
2099 } # end EXISTS
2100
2101 # ----------------------------------------------------------
2102 # DESTROY is used by TIEHASH and the Perl garbage collector,
2103 # ----------------------------------------------------------
2104 # Date Modification Author
2105 # ----------------------------------------------------------
2106 # 2000May09 Created method JW
2107 # ----------------------------------------------------------
2108 sub DESTROY
2109 {
2110 # my $self = shift;
2111 } # end if
2112
2113 # ----------------------------------------------------------
2114 # Sub: _make_filehandle
2115 #
2116 # Args: $thing
2117 # $thing An input source
2118 #
2119 # Description: Takes an input source - a filehandle,
2120 # filehandle glob, reference to a filehandle glob, IO::File
2121 # object or scalar filename - and returns a file handle to
2122 # read from it with.
2123 # ----------------------------------------------------------
2124 # Date Modification Author
2125 # ----------------------------------------------------------
2126 # 06Dec2001 Added to support input from any source JW
2127 # ----------------------------------------------------------
2128 sub _make_filehandle
2129 {
2130 my $self = shift;
2131
2132 #
2133 # This code is 'borrowed' from Lincoln D. Stein's GD.pm module
2134 # with modification for this module. Thanks Lincoln!
2135 #
2136
2137 no strict 'refs';
2138 my $thing = shift;
2139
2140 if ( ref($thing) eq "SCALAR" )
2141 {
2142 if ( eval { require IO::Scalar; $IO::Scalar::VERSION >= 2.109; } )
2143 {
2144 return IO::Scalar->new($thing);
2145 }
2146 else
2147 {
2148 warn "SCALAR reference as file descriptor requires IO::stringy "
2149 . "v2.109 or later"
2150 if ($^W);
2151 return;
2152 }
2153 }
2154
2155 return $thing if defined( fileno $thing );
2156
2157 # otherwise try qualifying it into caller's package
2158 my $fh = qualify_to_ref( $thing, caller(1) );
2159 return $fh if defined( fileno $fh );
2160
2161 # otherwise treat it as a file to open; 3-arg open so the filename is
2162 # not interpreted as a command or redirect
2163 $fh = gensym;
2164 open( $fh, '<', $thing ) || return;
2165
2166 return $fh;
2167 } # end _make_filehandle
2168
2169 ############################################################
2170 #
2171 # INTERNAL PACKAGE: Config::IniFiles::_section
2172 #
2173 # Description:
2174 # This package is used to provide a single-level TIEHASH
2175 # interface to the sections in the IniFile. When tied, the
2176 # user wants to look at thinks like $ini{sec}{parm}, but the
2177 # TIEHASH only provides one level of hash interface, so the
2178 # root object gets asked for a $ini{sec} and must return a
2179 # has reference that accurately covers the '{parm}' part.
2180 #
2181 # This package is only used when tied and is inter-woven
2182 # between the sections and their parameters when the TIEHASH
2183 # method is called by Perl. It's a very simple implementation
2184 # of a tied hash object that simply maps onto the object API.
2185 #
2186 ############################################################
2187 # Date Modification Author
2188 # ----------------------------------------------------------
2189 # 2000.May.09 Created to excapsulate TIEHASH interface JW
2190 ############################################################
2191 package Config::IniFiles::_section;
2192
2193 use strict;
2194 use warnings;
2195 use Carp;
2196 use vars qw( $VERSION );
2197
2198 $Config::IniFiles::_section::VERSION = 2.16;
2199
2200 # ----------------------------------------------------------
2201 # Sub: Config::IniFiles::_section::TIEHASH
2202 #
2203 # Args: $class, $config, $section
2204 # $class The class that this is being tied to.
2205 # $config The parent Config::IniFiles object
2206 # $section The section this tied object refers to
2207 #
2208 # Description: Builds the object that implements accesses to
2209 # the tied hash.
2210 # ----------------------------------------------------------
2211 # Date Modification Author
2212 # ----------------------------------------------------------
2213 # ----------------------------------------------------------
2214 sub TIEHASH
2215 {
2216 my $proto = shift;
2217 my $class = ref($proto) || $proto;
2218 my ( $config, $section ) = @_;
2219
2220 # Make a new object
2221 return bless { config => $config, section => $section }, $class;
2222 } # end TIEHASH
2223
2224 # ----------------------------------------------------------
2225 # Sub: Config::IniFiles::_section::FETCH
2226 #
2227 # Args: $key
2228 # $key The name of the key whose value to get
2229 #
2230 # Description: Returns the value associated with $key. If
2231 # the value is a list, returns a list reference.
2232 # ----------------------------------------------------------
2233 # Date Modification Author
2234 # ----------------------------------------------------------
2235 # 2000Jun15 Fixed bugs in -default handler JW
2236 # 2000Dec07 Fixed another bug in -deault handler JW
2237 # 2002Jul04 Returning scalar values (Bug:447532) AS
2238 # ----------------------------------------------------------
2239 sub FETCH
2240 {
2241 my ( $self, $key ) = @_;
2242 my @retval = $self->{config}->val( $self->{section}, $key );
2243 return ( @retval <= 1 ) ? $retval[0] : \@retval;
2244 } # end FETCH
2245
2246 # ----------------------------------------------------------
2247 # Sub: Config::IniFiles::_section::STORE
2248 #
2249 # Args: $key, @val
2250 # $key The key under which to store the value
2251 # @val The value to store, either an array or a scalar
2252 #
2253 # Description: Sets the value for the specified $key
2254 # ----------------------------------------------------------
2255 # Date Modification Author
2256 # ----------------------------------------------------------
2257 # 2001Apr04 Fixed -nocase bug JW
2258 # ----------------------------------------------------------
2259 sub STORE
2260 {
2261 my ( $self, $key, @val ) = @_;
2262 return $self->{config}->newval( $self->{section}, $key, @val );
2263 } # end STORE
2264
2265 # ----------------------------------------------------------
2266 # Sub: Config::IniFiles::_section::DELETE
2267 #
2268 # Args: $key
2269 # $key The key to remove from the hash
2270 #
2271 # Description: Removes the specified key from the hash and
2272 # returns its former value.
2273 # ----------------------------------------------------------
2274 # Date Modification Author
2275 # ----------------------------------------------------------
2276 # 2001Apr04 Fixed -nocase bug JW
2277 # ----------------------------------------------------------
2278 sub DELETE
2279 {
2280 my ( $self, $key ) = @_;
2281 my $retval = $self->{config}->val( $self->{section}, $key );
2282 $self->{config}->delval( $self->{section}, $key );
2283 return $retval;
2284 } # end DELETE
2285
2286 # ----------------------------------------------------------
2287 # Sub: Config::IniFiles::_section::CLEAR
2288 #
2289 # Args: (None)
2290 #
2291 # Description: Empties the entire hash
2292 # ----------------------------------------------------------
2293 # Date Modification Author
2294 # ----------------------------------------------------------
2295 # ----------------------------------------------------------
2296 sub CLEAR
2297 {
2298 my ($self) = @_;
2299 return $self->{config}->DeleteSection( $self->{section} );
2300 } # end CLEAR
2301
2302 # ----------------------------------------------------------
2303 # Sub: Config::IniFiles::_section::EXISTS
2304 #
2305 # Args: $key
2306 # $key The key to look for
2307 #
2308 # Description: Returns whether the key exists
2309 # ----------------------------------------------------------
2310 # Date Modification Author
2311 # ----------------------------------------------------------
2312 # 2001Apr04 Fixed -nocase bug JW
2313 # ----------------------------------------------------------
2314 sub EXISTS
2315 {
2316 my ( $self, $key ) = @_;
2317 return $self->{config}->exists( $self->{section}, $key );
2318 } # end EXISTS
2319
2320 # ----------------------------------------------------------
2321 # Sub: Config::IniFiles::_section::FIRSTKEY
2322 #
2323 # Args: (None)
2324 #
2325 # Description: Returns the first key in the hash
2326 # ----------------------------------------------------------
2327 # Date Modification Author
2328 # ----------------------------------------------------------
2329 # ----------------------------------------------------------
2330 sub FIRSTKEY
2331 {
2332 my $self = shift;
2333
2334 $self->{tied_enumerator} = 0;
2335 return $self->NEXTKEY();
2336 } # end FIRSTKEY
2337
2338 # ----------------------------------------------------------
2339 # Sub: Config::IniFiles::_section::NEXTKEY
2340 #
2341 # Args: $last
2342 # $last The last key accessed by the iterator
2343 #
2344 # Description: Returns the next key in line
2345 # ----------------------------------------------------------
2346 # Date Modification Author
2347 # ----------------------------------------------------------
2348 # ----------------------------------------------------------
2349 sub NEXTKEY
2350 {
2351 my $self = shift;
2352 my ($last) = @_;
2353
2354 my $i = $self->{tied_enumerator}++;
2355 my @keys = $self->{config}->Parameters( $self->{section} );
2356 my $key = $keys[$i];
2357 return if ( !defined $key );
2358 return wantarray ? ( $key, $self->FETCH($key) ) : $key;
2359 } # end NEXTKEY
2360
2361 # ----------------------------------------------------------
2362 # Sub: Config::IniFiles::_section::DESTROY
2363 #
2364 # Args: (None)
2365 #
2366 # Description: Called on cleanup
2367 # ----------------------------------------------------------
2368 # Date Modification Author
2369 # ----------------------------------------------------------
2370 # ----------------------------------------------------------
2371 sub DESTROY
2372 {
2373 # my $self = shift
2374 } # end DESTROY
2375
2376 1;
2377
2378
2379
2380 1;
2381
2382 # Please keep the following within the last four lines of the file
2383 #[JW for editor]:mode=perl:tabSize=8:indentSize=2:noTabs=true:indentOnEnter=true:
2384
2385 __END__
2386
2387 =pod
2388
2389 =encoding UTF-8
2390
2391 =head1 NAME
2392
2393 Config::IniFiles - A module for reading .ini-style configuration files.
2394
2395 =head1 VERSION
2396
2397 version 3.003000
2398
2399 =head1 SYNOPSIS
2400
2401 use Config::IniFiles;
2402 my $cfg = Config::IniFiles->new( -file => "/path/configfile.ini" );
2403 print "The value is " . $cfg->val( 'Section', 'Parameter' ) . "."
2404 if $cfg->val( 'Section', 'Parameter' );
2405
2406 =head1 DESCRIPTION
2407
2408 Config::IniFiles provides a way to have readable configuration files outside
2409 your Perl script. Configurations can be imported (inherited, stacked,...),
2410 sections can be grouped, and settings can be accessed from a tied hash.
2411
2412 =head1 FILE FORMAT
2413
2414 INI files consist of a number of sections, each preceded with the
2415 section name in square brackets, followed by parameter names and
2416 their values.
2417
2418 [a section]
2419 Parameter=Value
2420
2421 [section 2]
2422 AnotherParameter=Some value
2423 Setting=Something else
2424 Parameter=Different scope than the one in the first section
2425
2426 The first non-blank character of the line indicating a section must
2427 be a left bracket and the last non-blank character of a line indicating
2428 a section must be a right bracket. The characters making up the section
2429 name can be any symbols at all. However section names must be unique.
2430
2431 Parameters are specified in each section as Name=Value. Any spaces
2432 around the equals sign will be ignored, and the value extends to the
2433 end of the line (including any whitespace at the end of the line.
2434 Parameter names are localized to the namespace of the section, but must
2435 be unique within a section.
2436
2437 Both the hash mark (#) and the semicolon (;) are comment characters.
2438 by default (this can be changed by configuration). Lines that begin with
2439 either of these characters will be ignored. Any amount of whitespace may
2440 precede the comment character.
2441
2442 Multi-line or multi-valued parameters may also be defined ala UNIX
2443 "here document" syntax:
2444
2445 Parameter=<<EOT
2446 value/line 1
2447 value/line 2
2448 EOT
2449
2450 You may use any string you want in place of "EOT". Note that whatever
2451 follows the "<<" and what appears at the end of the text MUST match
2452 exactly, including any trailing whitespace.
2453
2454 Alternately, as a configuration option (default is off), continuation
2455 lines can be allowed:
2456
2457 [Section]
2458 Parameter=this parameter \
2459 spreads across \
2460 a few lines
2461
2462 =head1 USAGE -- Object Interface
2463
2464 Get a new Config::IniFiles object with the I<new> method:
2465
2466 $cfg = Config::IniFiles->new( -file => "/path/config_file.ini" );
2467 $cfg = new Config::IniFiles -file => "/path/config_file.ini";
2468
2469 Optional named parameters may be specified after the configuration
2470 file name. See the I<new> in the B<METHODS> section, below.
2471
2472 Values from the config file are fetched with the val method:
2473
2474 $value = $cfg->val('Section', 'Parameter');
2475
2476 If you want a multi-line/value field returned as an array, just
2477 specify an array as the receiver:
2478
2479 @values = $cfg->val('Section', 'Parameter');
2480
2481 =head1 METHODS
2482
2483 =head2 new ( [-option=>value ...] )
2484
2485 Returns a new configuration object (or "undef" if the configuration
2486 file has an error, in which case check the global C<@Config::IniFiles::errors>
2487 array for reasons why). One Config::IniFiles object is required per configuration
2488 file. The following named parameters are available:
2489
2490 =over 10
2491
2492 =item I<-file> filename
2493
2494 Specifies a file to load the parameters from. This 'file' may actually be
2495 any of the following things:
2496
2497 1) the pathname of a file
2498
2499 $cfg = Config::IniFiles->new( -file => "/path/to/config_file.ini" );
2500
2501 2) a simple filehandle
2502
2503 $cfg = Config::IniFiles->new( -file => STDIN );
2504
2505 3) a filehandle glob
2506
2507 open( CONFIG, "/path/to/config_file.ini" );
2508 $cfg = Config::IniFiles->new( -file => *CONFIG );
2509
2510 4) a reference to a glob
2511
2512 open( CONFIG, "/path/to/config_file.ini" );
2513 $cfg = Config::IniFiles->new( -file => \*CONFIG );
2514
2515 5) an IO::File object
2516
2517 $io = IO::File->new( "/path/to/config_file.ini" );
2518 $cfg = Config::IniFiles->new( -file => $io );
2519
2520 or
2521
2522 open my $fh, '<', "/path/to/config_file.ini" or die $!;
2523 $cfg = Config::IniFiles->new( -file => $fh );
2524
2525 6) A reference to a scalar (requires newer versions of IO::Scalar)
2526
2527 $ini_file_contents = <<EOT
2528 [section name]
2529 Parameter=A value
2530 Setting=Another value
2531 EOT
2532
2533 $cfg = Config::IniFiles->new( -file => \$ini_file_contents );
2534
2535 If this option is not specified, (i.e. you are creating a config file from scratch)
2536 you must specify a target file using L<SetFileName> in order to save the parameters.
2537
2538 The passed filehandles can be opened using an encoding-specifying mode such as
2539 C<< '<+:encoding(utf8)' >> as demonstrated and tested in C<t/19utf8.t> :
2540 L<GitHub link|https://github.com/shlomif/perl-Config-IniFiles/blob/master/config-inifiles/t/19utf8.t>
2541 L<MetaCPAN link|https://metacpan.org/release/SHLOMIF/Config-IniFiles-3.002000/source/t/19utf8.t> .
2542
2543 =item I<-default> section
2544
2545 Specifies a section to be used for default values. For example, in the
2546 following configuration file, if you look up the "permissions" parameter
2547 in the "joe" section, there is none.
2548
2549 [all]
2550 permissions=Nothing
2551
2552 [jane]
2553 name=Jane
2554 permissions=Open files
2555
2556 [joe]
2557 name=Joseph
2558
2559 If you create your Config::IniFiles object with a default section of "all" like this:
2560
2561 $cfg = Config::IniFiles->new( -file => "file.ini", -default => "all" );
2562
2563 Then requesting a value for a "permissions" in the [joe] section will
2564 check for a value from [all] before returning undef.
2565
2566 $permissions = $cfg->val( "joe", "permissions"); // returns "Nothing"
2567
2568 =item I<-fallback> section
2569
2570 Specifies a section to be used for parameters outside a section. Default is none.
2571 Without -fallback specified (which is the default), reading a configuration file
2572 which has a parameter outside a section will fail. With this set to, say,
2573 "GENERAL", this configuration:
2574
2575 wrong=wronger
2576
2577 [joe]
2578 name=Joseph
2579
2580 will be assumed as:
2581
2582 [GENERAL]
2583 wrong=wronger
2584
2585 [joe]
2586 name=Joseph
2587
2588 Note that Config::IniFiles will also omit the fallback section header when
2589 outputting such configuration.
2590
2591 =item I<-nocase> 0|1
2592
2593 Set -nocase => 1 to handle the config file in a case-insensitive
2594 manner (case in values is preserved, however). By default, config
2595 files are case-sensitive (i.e., a section named 'Test' is not the same
2596 as a section named 'test'). Note that there is an added overhead for
2597 turning off case sensitivity.
2598
2599 =item I<-import> object
2600
2601 This allows you to import or inherit existing setting from another
2602 Config::IniFiles object. When importing settings from another object,
2603 sections with the same name will be merged and parameters that are
2604 defined in both the imported object and the I<-file> will take the
2605 value of given in the I<-file>.
2606
2607 If a I<-default> section is also given on this call, and it does not
2608 coincide with the default of the imported object, the new default
2609 section will be used instead. If no I<-default> section is given,
2610 then the default of the imported object will be used.
2611
2612 =item I<-allowcontinue> 0|1
2613
2614 Set -allowcontinue => 1 to enable continuation lines in the config file.
2615 i.e. if a line ends with a backslash C<\>, then the following line is
2616 appended to the parameter value, dropping the backslash and the newline
2617 character(s).
2618
2619 Default behavior is to keep a trailing backslash C<\> as a parameter
2620 value. Note that continuation cannot be mixed with the "here" value
2621 syntax.
2622
2623 =item I<-allowempty> 0|1
2624
2625 If set to 1, then empty files are allowed at L<ReadConfig|ReadConfig()>
2626 time. If set to 0 (the default), an empty configuration file is considered
2627 an error.
2628
2629 =item I<-negativedeltas> 0|1
2630
2631 If set to 1 (the default if importing this object from another one),
2632 parses and honors lines of the following form in the configuration
2633 file:
2634
2635 ; [somesection] is deleted
2636
2637 or
2638
2639 [inthissection]
2640 ; thisparameter is deleted
2641
2642 If set to 0 (the default if not importing), these comments are treated
2643 like ordinary ones.
2644
2645 The L<WriteConfig|WriteConfig($filename, -delta=>1)> form will output such
2646 comments to indicate deleted sections or parameters. This way,
2647 reloading a delta file using the same imported object produces the
2648 same results in memory again. See L<IMPORT / DELTA FEATURES> for more
2649 details.
2650
2651 =item I<-commentchar> 'char'
2652
2653 The default comment character is C<#>. You may change this by specifying
2654 this option to another character. This can be any character except
2655 alphanumeric characters, square brackets or the "equal" sign.
2656
2657 =item I<-allowedcommentchars> 'chars'
2658
2659 Allowed default comment characters are C<#> and C<;>. By specifying this
2660 option you may change the range of characters that are used to denote a
2661 comment line to include any set of characters
2662
2663 Note: that the character specified by B<-commentchar> (see above) is
2664 I<always> part of the allowed comment characters.
2665
2666 Note 2: The given string is evaluated as a regular expression character
2667 class, so '\' must be escaped if you wish to use it.
2668
2669 =item I<-reloadwarn> 0|1
2670
2671 Set -reloadwarn => 1 to enable a warning message (output to STDERR)
2672 whenever the config file is reloaded. The reload message is of the
2673 form:
2674
2675 PID <PID> reloading config file <file> at YYYY.MM.DD HH:MM:SS
2676
2677 Default behavior is to not warn (i.e. -reloadwarn => 0).
2678
2679 This is generally only useful when using Config::IniFiles in a server
2680 or daemon application. The application is still responsible for determining
2681 when the object is to be reloaded.
2682
2683 =item I<-nomultiline> 0|1
2684
2685 Set -nomultiline => 1 to output multi-valued parameter as:
2686
2687 param=value1
2688 param=value2
2689
2690 instead of the default:
2691
2692 param=<<EOT
2693 value1
2694 value2
2695 EOT
2696
2697 As the latter might not be compatible with all applications.
2698
2699 =item I<-handle_trailing_comment> 0|1
2700
2701 Set -handle_trailing_comment => 1 to enable support of parameter trailing
2702 comments.
2703
2704 For example, if we have a parameter line like this:
2705
2706 param1=value1;comment1
2707
2708 by default, handle_trailing_comment will be set to B<0>, and we will get
2709 I<value1;comment1> as the value of I<param1>. If we have
2710 -handle_trailing_comment set to B<1>, then we will get I<value1>
2711 as the value for I<param1>, and I<comment1> as the trailing comment of
2712 I<param1>.
2713
2714 Set and get methods for trailing comments are provided as
2715 L</SetParameterTrailingComment> and L</GetParameterTrailingComment>.
2716
2717 =item I<-php_compat> 0|1
2718
2719 Set -php_compat => 1 to enable support for PHP like configfiles.
2720
2721 The differences between parse_ini_file and Config::IniFiles are:
2722
2723 # parse_ini_file
2724 [group]
2725 val1="value"
2726 val2[]=1
2727 val2[]=2
2728
2729 vs
2730
2731 # Config::IniFiles
2732 [group]
2733 val1=value
2734 val2=1
2735 val2=2
2736
2737 This option only affect parsing, not writing new configfiles.
2738
2739 Some features from parse_ini_file are not compatible:
2740
2741 [group]
2742 val1="val"'ue'
2743 val1[key]=1
2744
2745 =back
2746
2747 =head2 val ($section, $parameter [, $default] )
2748
2749 Returns the value of the specified parameter (C<$parameter>) in section
2750 C<$section>, returns undef (or C<$default> if specified) if no section or
2751 no parameter for the given section exists.
2752
2753 If you want a multi-line/value field returned as an array, just
2754 specify an array as the receiver:
2755
2756 @values = $cfg->val('Section', 'Parameter');
2757
2758 A multi-line/value field that is returned in a scalar context will be
2759 joined using $/ (input record separator, default is \n) if defined,
2760 otherwise the values will be joined using \n.
2761
2762 =head2 exists($section, $parameter)
2763
2764 True if and only if there exists a section C<$section>, with
2765 a parameter C<$parameter> inside, not counting default values.
2766
2767 =head2 push ($section, $parameter, $value, [ $value2, ...])
2768
2769 Pushes new values at the end of existing value(s) of parameter
2770 C<$parameter> in section C<$section>. See below for methods to write
2771 the new configuration back out to a file.
2772
2773 You may not set a parameter that didn't exist in the original
2774 configuration file. B<push> will return I<undef> if this is
2775 attempted. See B<newval> below to do this. Otherwise, it returns 1.
2776
2777 =head2 setval ($section, $parameter, $value, [ $value2, ... ])
2778
2779 Sets the value of parameter C<$parameter> in section C<$section> to
2780 C<$value> (or to a set of values). See below for methods to write
2781 the new configuration back out to a file.
2782
2783 You may not set a parameter that didn't exist in the original
2784 configuration file. B<setval> will return I<undef> if this is
2785 attempted. See B<newval> below to do this. Otherwise, it returns 1.
2786
2787 =head2 newval($section, $parameter, $value [, $value2, ...])
2788
2789 Assigns a new value, C<$value> (or set of values) to the
2790 parameter C<$parameter> in section C<$section> in the configuration
2791 file.
2792
2793 =head2 delval($section, $parameter)
2794
2795 Deletes the specified parameter from the configuration file
2796
2797 =head2 ReadConfig
2798
2799 Forces the configuration file to be re-read. Returns undef if the
2800 file can not be opened, no filename was defined (with the C<-file>
2801 option) when the object was constructed, or an error occurred while
2802 reading.
2803
2804 If an error occurs while parsing the INI file the @Config::IniFiles::errors
2805 array will contain messages that might help you figure out where the
2806 problem is in the file.
2807
2808 =head2 Sections
2809
2810 Returns an array containing section names in the configuration file.
2811 If the I<nocase> option was turned on when the config object was
2812 created, the section names will be returned in lowercase.
2813
2814 =head2 SectionExists ( $sect_name )
2815
2816 Returns 1 if the specified section exists in the INI file, 0 otherwise (undefined if section_name is not defined).
2817
2818 =head2 AddSection ( $sect_name )
2819
2820 Ensures that the named section exists in the INI file. If the section already
2821 exists, nothing is done. In this case, the "new" section will possibly contain
2822 data already.
2823
2824 If you really need to have a new section with no parameters in it, check that
2825 the name that you're adding isn't in the list of sections already.
2826
2827 =head2 DeleteSection ( $sect_name )
2828
2829 Completely removes the entire section from the configuration.
2830
2831 =head2 RenameSection ( $old_section_name, $new_section_name, $include_groupmembers)
2832
2833 Renames a section if it does not already exist, optionally including groupmembers
2834
2835 =head2 CopySection ( $old_section_name, $new_section_name, $include_groupmembers)
2836
2837 Copies one section to another optionally including groupmembers
2838
2839 =head2 Parameters ($sect_name)
2840
2841 Returns an array containing the parameters contained in the specified
2842 section.
2843
2844 =head2 Groups
2845
2846 Returns an array containing the names of available groups.
2847
2848 Groups are specified in the config file as new sections of the form
2849
2850 [GroupName MemberName]
2851
2852 This is useful for building up lists. Note that parameters within a
2853 "member" section are referenced normally (i.e., the section name is
2854 still "Groupname Membername", including the space) - the concept of
2855 Groups is to aid people building more complex configuration files.
2856
2857 =head2 SetGroupMember ( $sect )
2858
2859 Makes sure that the specified section is a member of the appropriate group.
2860
2861 Only intended for use in newval.
2862
2863 =head2 RemoveGroupMember ( $sect )
2864
2865 Makes sure that the specified section is no longer a member of the
2866 appropriate group. Only intended for use in DeleteSection.
2867
2868 =head2 GroupMembers ($group)
2869
2870 Returns an array containing the members of specified $group. Each element
2871 of the array is a section name. For example, given the sections
2872
2873 [Group Element 1]
2874 ...
2875
2876 [Group Element 2]
2877 ...
2878
2879 GroupMembers would return ("Group Element 1", "Group Element 2").
2880
2881 =head2 SetWriteMode ($mode)
2882
2883 Sets the mode (permissions) to use when writing the INI file.
2884
2885 $mode must be a string representation of the octal mode.
2886
2887 =head2 GetWriteMode ($mode)
2888
2889 Gets the current mode (permissions) to use when writing the INI file.
2890
2891 $mode is a string representation of the octal mode.
2892
2893 =head2 WriteConfig ($filename [, %options])
2894
2895 Writes out a new copy of the configuration file. A temporary file
2896 is written out and then renamed to the specified filename. Also see
2897 B<BUGS> below.
2898
2899 If C<-delta> is set to a true value in %options, and this object was
2900 imported from another (see L</new>), only the differences between this
2901 object and the imported one will be recorded. Negative deltas will be
2902 encoded into comments, so that a subsequent invocation of I<new()>
2903 with the same imported object produces the same results (see the
2904 I<-negativedeltas> option in L</new>).
2905
2906 C<%options> is not required.
2907
2908 Returns true on success, C<undef> on failure.
2909
2910 =head2 RewriteConfig
2911
2912 Same as WriteConfig, but specifies that the original configuration
2913 file should be rewritten.
2914
2915 =head2 GetFileName
2916
2917 Returns the filename associated with this INI file.
2918
2919 If no filename has been specified, returns undef.
2920
2921 =head2 SetFileName ($filename)
2922
2923 If you created the Config::IniFiles object without initialising from
2924 a file, or if you just want to change the name of the file to use for
2925 ReadConfig/RewriteConfig from now on, use this method.
2926
2927 Returns $filename if that was a valid name, undef otherwise.
2928
2929 =head2 $ini->OutputConfigToFileHandle($fh, $delta)
2930
2931 Writes OutputConfig to the $fh filehandle. $delta should be set to 1
2932 1 if writing only delta. This is a newer and safer version of
2933 C<OutputConfig()> and one is encouraged to use it instead.
2934
2935 =head2 $ini->OutputConfig($delta)
2936
2937 Writes OutputConfig to STDOUT. Use select() to redirect STDOUT to
2938 the output target before calling this function. Optional argument
2939 should be set to 1 if writing only a delta. Also see OutputConfigToFileHandle
2940
2941 =head2 SetSectionComment($section, @comment)
2942
2943 Sets the comment for section $section to the lines contained in @comment.
2944
2945 Each comment line will be prepended with the comment character (default
2946 is C<#>) if it doesn't already have a comment character (ie: if the
2947 line does not start with whitespace followed by an allowed comment
2948 character, default is C<#> and C<;>).
2949
2950 To clear a section comment, use DeleteSectionComment ($section)
2951
2952 =head2 GetSectionComment ($section)
2953
2954 Returns a list of lines, being the comment attached to section $section. In
2955 scalar context, returns a string containing the lines of the comment separated
2956 by newlines.
2957
2958 The lines are presented as-is, with whatever comment character was originally
2959 used on that line.
2960
2961 =head2 DeleteSectionComment ($section)
2962
2963 Removes the comment for the specified section.
2964
2965 =head2 SetParameterComment ($section, $parameter, @comment)
2966
2967 Sets the comment attached to a particular parameter.
2968
2969 Any line of @comment that does not have a comment character will be
2970 prepended with one. See L</SetSectionComment($section, @comment)> above
2971
2972 =head2 GetParameterComment ($section, $parameter)
2973
2974 Gets the comment attached to a parameter. In list context returns all
2975 comments - in scalar context returns them joined by newlines.
2976
2977 =head2 DeleteParameterComment ($section, $parameter)
2978
2979 Deletes the comment attached to a parameter.
2980
2981 =head2 GetParameterEOT ($section, $parameter)
2982
2983 Accessor method for the EOT text (in fact, style) of the specified parameter. If any text is used as an EOT mark, this will be returned. If the parameter was not recorded using HERE style multiple lines, GetParameterEOT returns undef.
2984
2985 =head2 $cfg->SetParameterEOT ($section, $parameter, $EOT)
2986
2987 Accessor method for the EOT text for the specified parameter. Sets the HERE style marker text to the value $EOT. Once the EOT text is set, that parameter will be saved in HERE style.
2988
2989 To un-set the EOT text, use DeleteParameterEOT ($section, $parameter).
2990
2991 =head2 DeleteParameterEOT ($section, $parameter)
2992
2993 Removes the EOT marker for the given section and parameter.
2994 When writing a configuration file, if no EOT marker is defined
2995 then "EOT" is used.
2996
2997 =head2 SetParameterTrailingComment ($section, $parameter, $cmt)
2998
2999 Set the end trailing comment for the given section and parameter.
3000 If there is a old comment for the parameter, it will be
3001 overwritten by the new one.
3002
3003 If there is a new parameter trailing comment to be added, the
3004 value should be added first.
3005
3006 =head2 GetParameterTrailingComment ($section, $parameter)
3007
3008 An accessor method to read the trailing comment after the parameter.
3009 The trailing comment will be returned if there is one. A null string
3010 will be returned if the parameter exists but there is no comment for it.
3011 otherwise, L<undef> will be returned.
3012
3013 =head2 Delete
3014
3015 Deletes the entire configuration file in memory.
3016
3017 =head1 USAGE -- Tied Hash
3018
3019 =head2 tie %ini, 'Config::IniFiles', (-file=>$filename, [-option=>value ...] )
3020
3021 Using C<tie>, you can tie a hash to a B<Config::IniFiles> object. This creates a new
3022 object which you can access through your hash, so you use this instead of the
3023 B<new> method. This actually creates a hash of hashes to access the values in
3024 the INI file. The options you provide through C<tie> are the same as given for
3025 the B<new> method, above.
3026
3027 Here's an example:
3028
3029 use Config::IniFiles;
3030
3031 my %ini;
3032 tie %ini, 'Config::IniFiles', ( -file => "/path/configfile.ini" );
3033
3034 print "We have $ini{Section}{Parameter}." if $ini{Section}{Parameter};
3035
3036 Accessing and using the hash works just like accessing a regular hash and
3037 many of the object methods are made available through the hash interface.
3038
3039 For those methods that do not coincide with the hash paradigm, you can use
3040 the Perl C<tied> function to get at the underlying object tied to the hash
3041 and call methods on that object. For example, to write the hash out to a new
3042 ini file, you would do something like this:
3043
3044 tied( %ini )->WriteConfig( "/newpath/newconfig.ini" ) ||
3045 die "Could not write settings to new file.";
3046
3047 =head2 $val = $ini{$section}{$parameter}
3048
3049 Returns the value of $parameter in $section.
3050
3051 Multiline values accessed through a hash will be returned
3052 as a list in list context and a concatenated value in scalar
3053 context.
3054
3055 =head2 $ini{$section}{$parameter} = $value;
3056
3057 Sets the value of C<$parameter> in C<$section> to C<$value>.
3058
3059 To set a multiline or multi-value parameter just assign an
3060 array reference to the hash entry, like this:
3061
3062 $ini{$section}{$parameter} = [$value1, $value2, ...];
3063
3064 If the parameter did not exist in the original file, it will
3065 be created. However, Perl does not seem to extend autovivification
3066 to tied hashes. That means that if you try to say
3067
3068 $ini{new_section}{new_paramters} = $val;
3069
3070 and the section 'new_section' does not exist, then Perl won't
3071 properly create it. In order to work around this you will need
3072 to create a hash reference in that section and then assign the
3073 parameter value. Something like this should do nicely:
3074
3075 $ini{new_section} = {};
3076 $ini{new_section}{new_paramters} = $val;
3077
3078 =head2 %hash = %{$ini{$section}}
3079
3080 Using the tie interface, you can copy whole sections of the
3081 ini file into another hash. Note that this makes a copy of
3082 the entire section. The new hash in no longer tied to the
3083 ini file, In particular, this means -default and -nocase
3084 settings will not apply to C<%hash>.
3085
3086 =head2 $ini{$section} = {}; %{$ini{$section}} = %parameters;
3087
3088 Through the hash interface, you have the ability to replace
3089 the entire section with a new set of parameters. This call
3090 will fail, however, if the argument passed in NOT a hash
3091 reference. You must use both lines, as shown above so that
3092 Perl recognizes the section as a hash reference context
3093 before COPYing over the values from your C<%parameters> hash.
3094
3095 =head2 delete $ini{$section}{$parameter}
3096
3097 When tied to a hash, you can use the Perl C<delete> function
3098 to completely remove a parameter from a section.
3099
3100 =head2 delete $ini{$section}
3101
3102 The tied interface also allows you to delete an entire
3103 section from the ini file using the Perl C<delete> function.
3104
3105 =head2 %ini = ();
3106
3107 If you really want to delete B<all> the items in the ini file, this
3108 will do it. Of course, the changes won't be written to the actual
3109 file unless you call B<RewriteConfig> on the object tied to the hash.
3110
3111 =head2 Parameter names
3112
3113 =over 4
3114
3115 =item my @keys = keys %{$ini{$section}}
3116
3117 =item while (($k, $v) = each %{$ini{$section}}) {...}
3118
3119 =item if( exists %{$ini{$section}}, $parameter ) {...}
3120
3121 =back
3122
3123 When tied to a hash, you use the Perl C<keys> and C<each>
3124 functions to iteratively list the parameters (C<keys>) or
3125 parameters and their values (C<each>) in a given section.
3126
3127 You can also use the Perl C<exists> function to see if a
3128 parameter is defined in a given section.
3129
3130 Note that none of these will return parameter names that
3131 are part of the default section (if set), although accessing
3132 an unknown parameter in the specified section will return a
3133 value from the default section if there is one.
3134
3135 =head2 Section names
3136
3137 =over 4
3138
3139 =item foreach( keys %ini ) {...}
3140
3141 =item while (($k, $v) = each %ini) {...}
3142
3143 =item if( exists %ini, $section ) {...}
3144
3145 =back
3146
3147 When tied to a hash, you use the Perl C<keys> and C<each>
3148 functions to iteratively list the sections in the ini file.
3149
3150 You can also use the Perl C<exists> function to see if a
3151 section is defined in the file.
3152
3153 =head1 IMPORT / DELTA FEATURES
3154
3155 The I<-import> option to L</new> allows one to stack one
3156 I<Config::IniFiles> object on top of another (which might be itself
3157 stacked in turn and so on recursively, but this is beyond the
3158 point). The effect, as briefly explained in L</new>, is that the
3159 fields appearing in the composite object will be a superposition of
3160 those coming from the ``original'' one and the lines coming from the
3161 file, the latter taking precedence. For example, let's say that
3162 C<$master> and C<overlay> were created like this:
3163
3164 my $master = Config::IniFiles->new(-file => "master.ini");
3165 my $overlay = Config::IniFiles->new(-file => "overlay.ini",
3166 -import => $master);
3167
3168 If the contents of C<master.ini> and C<overlay.ini> are respectively
3169
3170 ; master.ini
3171 [section1]
3172 arg0=unchanged from master.ini
3173 arg1=val1
3174
3175 [section2]
3176 arg2=val2
3177
3178 and
3179
3180 ; overlay.ini
3181 [section1]
3182 arg1=overridden
3183
3184 Then C<< $overlay->val("section1", "arg1") >> is "overridden", while
3185 C<< $overlay->val("section1", "arg0") >> is "unchanged from
3186 master.ini".
3187
3188 This feature may be used to ship a ``global defaults'' configuration
3189 file for a Perl application, that can be overridden piecewise by a
3190 much shorter, per-site configuration file. Assuming UNIX-style path
3191 names, this would be done like this:
3192
3193 my $defaultconfig = Config::IniFiles->new
3194 (-file => "/usr/share/myapp/myapp.ini.default");
3195 my $config = Config::IniFiles->new
3196 (-file => "/etc/myapp.ini", -import => $defaultconfig);
3197 # Now use $config and forget about $defaultconfig in the rest of
3198 # the program
3199
3200 Starting with version 2.39, I<Config::IniFiles> also provides features
3201 to keep the importing / per-site configuration file small, by only
3202 saving those options that were modified by the running program. That
3203 is, if one calls
3204
3205 $overlay->setval("section1", "arg1", "anotherval");
3206 $overlay->newval("section3", "arg3", "val3");
3207 $overlay->WriteConfig('overlay.ini', -delta=>1);
3208
3209 C<overlay.ini> would now contain
3210
3211 ; overlay.ini
3212 [section1]
3213 arg1=anotherval
3214
3215 [section3]
3216 arg3=val3
3217
3218 This is called a I<delta file> (see L</WriteConfig>). The untouched
3219 [section2] and arg0 do not appear, and the config file is therefore
3220 shorter; while of course, reloading the configuration into C<$master>
3221 and C<$overlay>, either through C<< $overlay->ReadConfig() >> or through
3222 the same code as above (e.g. when application restarts), would yield
3223 exactly the same result had the overlay object been saved in whole to
3224 the file system.
3225
3226 The only problem with this delta technique is one cannot delete the
3227 default values in the overlay configuration file, only change
3228 them. This is solved by a file format extension, enabled by the
3229 I<-negativedeltas> option to L</new>: if, say, one would delete
3230 parameters like this,
3231
3232 $overlay->DeleteSection("section2");
3233 $overlay->delval("section1", "arg0");
3234 $overlay->WriteConfig('overlay.ini', -delta=>1);
3235
3236 The I<overlay.ini> file would now read:
3237
3238 ; overlay.ini
3239 [section1]
3240 ; arg0 is deleted
3241 arg1=anotherval
3242
3243 ; [section2] is deleted
3244
3245 [section3]
3246 arg3=val3
3247
3248 Assuming C<$overlay> was later re-read with C<< -negativedeltas => 1 >>,
3249 the parser would interpret the deletion comments to yield the correct
3250 result, that is, [section2] and arg0 would cease to exist in the
3251 C<$overlay> object.
3252
3253 =head1 DIAGNOSTICS
3254
3255 =head2 @Config::IniFiles::errors
3256
3257 Contains a list of errors encountered while parsing the configuration
3258 file. If the I<new> method returns B<undef>, check the value of this
3259 to find out what's wrong. This value is reset each time a config file
3260 is read.
3261
3262 =head1 BUGS
3263
3264 =over 3
3265
3266 =item *
3267
3268 The output from [Re]WriteConfig/OutputConfig might not be as pretty as
3269 it can be. Comments are tied to whatever was immediately below them.
3270 And case is not preserved for Section and Parameter names if the -nocase
3271 option was used.
3272
3273 =item *
3274
3275 No locking is done by [Re]WriteConfig. When writing servers, take
3276 care that only the parent ever calls this, and consider making your
3277 own backup.
3278
3279 =back
3280
3281 =head1 Data Structure
3282
3283 Note that this is only a reference for the package maintainers - one of the
3284 upcoming revisions to this package will include a total clean up of the
3285 data structure.
3286
3287 $iniconf->{cf} = "config_file_name"
3288 ->{startup_settings} = \%orginal_object_parameters
3289 ->{imported} = $object WHERE $object->isa("Config::IniFiles")
3290 ->{nocase} = 0
3291 ->{reloadwarn} = 0
3292 ->{sects} = \@sections
3293 ->{mysects} = \@sections
3294 ->{sCMT}{$sect} = \@comment_lines
3295 ->{group}{$group} = \@group_members
3296 ->{parms}{$sect} = \@section_parms
3297 ->{myparms}{$sect} = \@section_parms
3298 ->{EOT}{$sect}{$parm} = "end of text string"
3299 ->{pCMT}{$sect}{$parm} = \@comment_lines
3300 ->{v}{$sect}{$parm} = $value OR \@values
3301 ->{e}{$sect} = 1 OR does not exist
3302 ->{mye}{$sect} = 1 OR does not exists
3303
3304 =head1 AUTHOR and ACKNOWLEDGEMENTS
3305
3306 The original code was written by Scott Hutton.
3307 Then handled for a time by Rich Bowen (thanks!),
3308 and was later managed by Jeremy Wadsack (thanks!),
3309 and now is managed by Shlomi Fish ( L<http://www.shlomifish.org/> )
3310 with many contributions from various other people.
3311
3312 In particular, special thanks go to (in roughly chronological order):
3313
3314 Bernie Cosell, Alan Young, Alex Satrapa, Mike Blazer, Wilbert van de Pieterman,
3315 Steve Campbell, Robert Konigsberg, Scott Dellinger, R. Bernstein,
3316 Daniel Winkelmann, Pires Claudio, Adrian Phillips,
3317 Marek Rouchal, Luc St Louis, Adam Fischler, Kay Röpke, Matt Wilson,
3318 Raviraj Murdeshwar and Slaven Rezic, Florian Pfaff
3319
3320 Geez, that's a lot of people. And apologies to the folks who were missed.
3321
3322 If you want someone to bug about this, that would be:
3323
3324 Shlomi Fish <[email protected]>
3325
3326 If you want more information, or want to participate, go to:
3327
3328 L<http://sourceforge.net/projects/config-inifiles/>
3329
3330 Please submit bug reports using the Request Tracker interface at
3331 L<https://rt.cpan.org/Public/Dist/Display.html?Name=Config-IniFiles> .
3332
3333 Development discussion occurs on the mailing list
3334 [email protected], which you can subscribe
3335 to by going to the project web site (link above).
3336
3337 =head1 LICENSE
3338
3339 This software is copyright (c) 2000 by Scott Hutton and the rest of the
3340 Config::IniFiles contributors.
3341
3342 This is free software; you can redistribute it and/or modify it under
3343 the same terms as the Perl 5 programming language system itself.
3344
3345 =head1 AUTHOR
3346
3347 Shlomi Fish <[email protected]>
3348
3349 =head1 COPYRIGHT AND LICENSE
3350
3351 This software is copyright (c) 2000 by RBOW and others.
3352
3353 This is free software; you can redistribute it and/or modify it under
3354 the same terms as the Perl 5 programming language system itself.
3355
3356 =head1 BUGS
3357
3358 Please report any bugs or feature requests on the bugtracker website
3359 L<https://github.com/shlomif/perl-Config-IniFiles/issues>
3360
3361 When submitting a bug or request, please include a test-file or a
3362 patch to an existing test-file that illustrates the bug or desired
3363 feature.
3364
3365 =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
3366
3367 =head1 SUPPORT
3368
3369 =head2 Perldoc
3370
3371 You can find documentation for this module with the perldoc command.
3372
3373 perldoc Config::IniFiles
3374
3375 =head2 Websites
3376
3377 The following websites have more information about this module, and may be of help to you. As always,
3378 in addition to those websites please use your favorite search engine to discover more resources.
3379
3380 =over 4
3381
3382 =item *
3383
3384 MetaCPAN
3385
3386 A modern, open-source CPAN search engine, useful to view POD in HTML format.
3387
3388 L<https://metacpan.org/release/Config-IniFiles>
3389
3390 =item *
3391
3392 RT: CPAN's Bug Tracker
3393
3394 The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
3395
3396 L<https://rt.cpan.org/Public/Dist/Display.html?Name=Config-IniFiles>
3397
3398 =item *
3399
3400 CPANTS
3401
3402 The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
3403
3404 L<http://cpants.cpanauthors.org/dist/Config-IniFiles>
3405
3406 =item *
3407
3408 CPAN Testers
3409
3410 The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
3411
3412 L<http://www.cpantesters.org/distro/C/Config-IniFiles>
3413
3414 =item *
3415
3416 CPAN Testers Matrix
3417
3418 The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
3419
3420 L<http://matrix.cpantesters.org/?dist=Config-IniFiles>
3421
3422 =item *
3423
3424 CPAN Testers Dependencies
3425
3426 The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
3427
3428 L<http://deps.cpantesters.org/?module=Config::IniFiles>
3429
3430 =back
3431
3432 =head2 Bugs / Feature Requests
3433
3434 Please report any bugs or feature requests by email to C<bug-config-inifiles at rt.cpan.org>, or through
3435 the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=Config-IniFiles>. You will be automatically notified of any
3436 progress on the request by the system.
3437
3438 =head2 Source Code
3439
3440 The code is open to the world, and available for you to hack on. Please feel free to browse it and play
3441 with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
3442 from your repository :)
3443
3444 L<https://github.com/shlomif/perl-Config-IniFiles>
3445
3446 git clone git://github.com/shlomif/perl-Config-IniFiles.git
3447
3448 =cut