This file is indexed.

/usr/share/perl5/Config/Scoped.pod is in libconfig-scoped-perl 0.22-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
=head1 NAME

Config::Scoped - feature rich configuration file parser

=head1 SYNOPSIS

  use Config::Scoped;

  $cs = Config::Scoped->new( file => $config_file, ... );
  $cfg_hash = $cs->parse;


=head1 ABSTRACT


B<Config::Scoped> is a configuration file parser.

=head2 Features

=over 4

=item *

recursive data structures with scalars, lists, and hashes

=item *

simplified syntax with minimal punctuation

=item *

parses many Perl data structures without B<eval>, B<do> or B<require>

=item *

Perl quoting syntax: single quotes (B<''>), double quotes(B<"">), and here-docs (B<< <<EOF >>)

=item *

Perl code evaluation in B<Safe> compartments

=item *

parses ISC named and dhcpd config files

=item *

include files with recursion checks

=item *

controlled macro expansion in double quoted tokens

=item *

lexically scoped parameter assignments and directives

=item *

duplicate macro, parameter, and declaration checks

=item *

file permission and ownership safety checks

=item *

fine control over error checking

=item *

error messages report config file names and line numbers

=item *

exception-based error handling

=item *

based on B<Parse::RecDescent>

=item *

configuration caching with MD5 checksums on the original files

=item *

may be subclassed to build parsers with specialized features

=back

=head1 REQUIRES

=over 4

=item *

B<Parse::RecDescent>

=item *

B<Error>

=back


=head1 EXPORTS

Nothing.

=head1 METHODS

=over 4


=item B<< Config::Scoped->new >>


  $cs = Config::Scoped->new(
    file     => $config_file,
    lc       => $lc,
    safe     => $compartment,
    warnings => $warnings,
    your_key => $your_value, { ... },
  );

Creates and returns a new B<Config::Scoped> object. The following parameters are optional.

=over 4

=item B<$config_file>

The configuration file to parse. If omitted, then a B<$config_string> must be provided to the B<parse> method (see below).

=item B<$lc>

If true, all declaration and parameter names will be converted to lower case.

=item B<$compartment>

A B<Safe> compartment for evaluating Perl code blocks in the configuration file. Defaults to a B<Safe> compartment with no extra shares and the B<:default> operator tag.

=item B<$warnings>

may be the literal string B<'on'> or B<'off'> to set all warnings simultan.

Or define a hash reference with the following keys to set each warning as specified.

  $warnings = { declaration  => 'off',
                digests      => 'off',
                macro        => 'off',
                parameter    => 'off',
                permissions  => 'off',
                your_warning => 'off',
 };

All warnings are on by default.

=item B<Arbitrary key/value pairs>

will be stored in the B<$cs> object. This is useful primarily for subclassing.

=back

=item B<< $cs->parse >>

    $cfg_hash = $cs->parse;
    $cfg_hash = $cs->parse(text => $config_string);

Parses the configuration and returns a reference to the config hash.

The first form parses the B<$config_file> that was provided to the constructor. If B<$config_file> was not provided to the constructor, this form B<die>s.

The second form parses the B<$config_string>.

This method must only be called once.

=item B<< $cs->store_cache >>

    $cs->store_cache;
    $cs->store_cache(cache => $cache_file);

Stores the config hash on disk for rapid retrieval. If B<$config_file> was provided to the constructor, then the stored form includes checksums of B<$config_file> and any included files.

The first  form writes to B<$config_file.dump>
The second form writes to B<$cache_file>.

If B<$config_file> was not provided to the constructor, the first form B<die>s.

=item B<< $cs->retrieve_cache >>

    $cfg_hash = $cs->retrieve_cache;
    $cfg_hash = $cs->retrieve_cache>(cache => $cache_file);

Retrieves the B<$config> hash from a file that was created by B<store_cache>.

The first  form reads B<$config_file.dump>
The second form reads B<$cache_file>.

If B<$config_file> was not provided to the constructor, the first form B<die>s.

The stored file is subject to B<digests> and B<permissions> checks.

=item B<< $cs->set_warnings >>

    $cs->set_warnings(name => $name, switch => 'on|off');

Change warning for B<$name> after construction.

=item B<< $cs->warnings_on >>

    $on = $cs->warnings_on(name => $name);

Returns true if warning B<$name> is on. This is useful primarily for subclassing.

=back

=head1 EXCEPTIONS


All methods B<die> on error.

B<Config::Scoped::Error> defines a hierarchy of classes that represent B<Config::Scoped> errors. When a method detects an error, it creates an instance of the corresponding class and throws it. The error classes are all subclasses of B<Config::Scoped::Error>. See
L<Config::Scoped::Error> for the complete list.

If the exception is not caught, the program terminates, and B<Config::Scoped> prints the config file name and line number where the error was detected to B<STDERR>.


=head1 CONFIG FILE FORMAT

B<Config::Scoped> parses configuration files.

If we have a config file like

  % cat host.cfg
  host {
      name = cpan.org
      port = 22
  }
  %

we can parse it into Perl with code like

    $cs = Config::Scoped->new( file => 'host.cfg' );
    $cfg_hash = $cs->parse;

The result is always a hash ref. We'll call this the B<config hash>, and its contents for the example file above is:

    $cfg_hash = {
       host => {
          name => 'cpan.org',
          port => 22,
       }
      }

=head2 Config files and config strings

As described, B<Config::Scoped> can obtain a configuration from a B<$config_file>, passed to the constructor, or from a B<$config_string>, passed to the B<parse> method. For simplicity, we'll talk about parsing configuration files, distinguishing configuration strings only when necessary.

=head2 File layout

Config files are free-form text files.
Comments begin with B<#>, and extend to the end of the line.

=head2 Declarations

The top-level elements of a config file are called B<declarations>. A declaration consists of a name, followed by a block

  foo {
  }

  bar {
  }

The declaration names become keys in the config hash. The value of each key is another hash ref. The config shown above parses to

    $cfg_hash = {
       foo => {},
       bar => {},
      }

You can create additional levels in the config hash simply by listing successive declaration names before the block. This config

  dog hound {
  }

  dog beagle {
  }

  cat {
  }

parses to

    $cfg_hash = {
       dog => {
          hound  => {},
          beagle => {},
       },

       cat => {}
      }

Declarations may not be nested.

=head2 Parameters

The ultimate purpose of a configuration file is to provide data values for a program.  These values are specified by B<parameters>.

Parameters have the form

  name = value

and go inside declaration blocks. The

  name = value

parameters in a spec file become key and value pairs inside the declaration hashes in Perl code.

For example, this configuration

  dog {
      legs  = 4
      wings = 0
  }

  bird {
      legs  = 2
      wings = 2
  }

parses to

    $cfg_hash = {
       dog => {
          legs  => 4,
          wings => 0,
       },

       bird => {
          legs  => 2,
          wings => 2,
       }
      }

B<Parameter values> can be B<scalars>, B<lists> or B<hashes>.

Scalar values may be numbers or strings

  shape = square
  sides = 4

Lists values are enclosed in square brackets

  colors = [ red green blue ]
  primes = [ 2 3 5 7 11 13  ]

Hash values are enclosed in curly brackets

  capitals = {
        England => London
        France  => Paris
  }

A hash value is also called a B<hash block>.

Lists and hashes can be nested to arbitrary depth

  Europe {
     currency = euro
     
     cities   = {
        England => [ London Birmingham Liverpool ]
        France  => [ Paris Canne Calais ]
     }
   }

parses to

    $cfg_hash = {
       Europe => {
          currency => 'euro',

          cities => {
             England => [ 'London', 'Birmingham', 'Liverpool' ],
             France  => [ 'Paris',  'Canne',      'Calais' ],
          }
       }
      }

The B<Config::Scoped> data syntax is similar to the Perl data syntax, and B<Config::Scoped> will parse many Perl data structures. In general, B<Config::Scoped> requires less punctuation that Perl. Note that B<Config::Scoped> allows arrow (B<< => >>) or equals (B<=>) between hash keys and values, but not comma (B<,>)

  capitals = { England => London        # OK
               France  =  Paris         # OK
               Germany ,  Berlin        # error
             }


=head2 _GLOBAL

If a config file contains no declarations at all

  name = cpan.org
  port = 22

then any parameters will be placed in a B<_GLOBAL> declaration in the
config hash

   $cfg_hash = {
      _GLOBAL => {
         name => 'cpan.org',
         port => 22,
      }
     }

This allows very simple config files with just parameters and no
declarations.


=head2 Blocks, scoping and inheritance

Each declaration block in a config file creates a lexical scope. Parameters inside a declaration are scoped to that block. Parameters are inherited by all following declarations within their scope.

If all your animals have four legs, you can save some typing by writing

    legs = 4
    cat {}
    dog {}

which parses to

   $cfg_hash = {
      cat => { legs => 4 },
      dog => { legs => 4 },
     }

If some of your animals have two legs, you can create additional scopes with anonymous blocks to control inheritance

    {
      legs = 4
      cat {}
      dog {}
    }
    {
      legs = 2
      bird {}
    }

parses to

   $cfg_hash = {
      cat  => { legs => 4 },
      dog  => { legs => 4 },
      bird => { legs => 2 },
     }

Anonymous blocks may be nested.

Each hash block also creates a scope. The hash does not inherit parameters from outside its own scope.

=head2 Perl code evaluation

If you can't express what you need within the B<Config::Scoped> syntax, your escape hatch is

  eval { ... }

This does a Perl B<eval> on the block, and replaces the construct with the results of the B<eval>.

  start = eval { localtime }
  foo   = eval { warn 'foo,' if $debug; return 'bar' }

The block is evaluated in scalar context. However, it may return a list or hash reference, and the underlying list or hash can become a parameter value.

For example

  foo {
    list = eval { [ 1 .. 3 ]                 }
    hash = eval { { a => 1, b => 2, c => 3 } }
  }

parses to

   $cfg_hash = {
      foo => {
         list => [ 1, 2, 3 ],
         hash => { a => 1, b => 2, c => 3 },
      }
     }


The block is evaluated inside the parser's B<Safe> compartment. Variables can be made available to the B<eval> by sharing them with the compartment.

To set the B<$debug> variable in the example above, do 

    $compartment     = Safe->new('MY_SHARE');
    $MY_SHARE::debug = 1;

    $cs = Config::Scoped->new(
      file => 'config.txt',
      safe => $compartment,
    );

    $cfg_hash = $cs->parse;

Only global variables can be shared with a compartment; lexical variables cannot.

B<perl_code> is a synonym for B<eval>.


=head2 Tokens and quoting

A B<token> is a

=over 4

=item *

declaration name

=item *

parameter name

=item *

hash key

=item *

scalar value

=item *

macro name

=item *

macro value

=item *

include path

=item *

warning name

=back

Any token may be quoted.

Tokens that contain special characters must be quoted. The special characters are

  \s {} [] <> () ; , ' " = # %

B<Config::Scoped> uses the Perl quoting syntax.

Tokens may be quoted with either single or double quotes

  a = 'New York'
  b = "New Jersey\n"

Here-docs are supported

  a = <<EOT
  New York
  New Jersey
  EOT

but generalized quotes (B<q()>, B<qq()>, etc.) are not. Text in here-docs is regarded as single-quoted if the delimiter is enclosed in single quotes, and double-quoted if the delimiter is enclosed in double quotes or unquoted.

Double-quoted tokens are evaluated as Perl strings inside the parser's B<Safe> compartment. They are subject to the usual Perl backslash and variable interpolation, as well as macro expansion. Variables to be interpolated are passed via the B<Safe> compartment, as shown above in L</Perl code evaluation>. If you need a literal B<$> or B<@> in a double-quoted string, be sure to escape it with a backslash (B<\>) to suppress interpolation.

An

  eval { ... }

may appear anywhere that a token is expected. For example

  foo {
      eval { 'b' . 'c' } = 1
  }

parses to

    $cfg_hash = { foo => { bc => 1 } }

=head1 DIRECTIVES

B<Config::Scoped> has three directives: B<%macro>, B<%warning>, and B<%include>.

=head2 Macros

B<Config::Scoped> supports macros. A macro is defined with

  %macro name value

Macros may be defined

=over 4

=item *

at file scope

=item *

within anonymous blocks

=item *

within declaration blocks

=item *

within hash blocks

=back

Macros defined within blocks are lexically scoped to those blocks.

Macro substitution occurs

=over 4

=item *

within B<any> double-quoted text

=item *

within the B<entirety> of Perl B<eval> blocks

=item *

nowhere else

=back


=head2 Include files

B<Config::Scoped> supports include files.

To include one config file within another, write

  %include path/to/file

B<%include> directives may appear

=over 4

=item *

at file scope

=item *

within anonymous blocks

=item *

nowhere else

=back

In particular, B<%include> directives may not appear within declaration blocks or hash blocks.

Parameters and macros in include files are imported to the current scope. You can control this scope with an anonymous block

  {
    %include dog.cfg
    dog { }  # sees imports from dog.cfg
  }
  bird { }   # does not see imports from dog.cfg


Warnings are scoped to the included file and do not leak to the parent file.

Pathnames are either

=over 4

=item *

absolute

=item *

relative to the dirname of the current configuration file

=back

For example, this config

    # in configuration file /etc/myapp/global.cfg
    %include shared.cfg

includes the file F</etc/myapp/shared.cfg>.

When parsing a configuration string, the path is relative to the current working directory.

Include files are not actually included as text. Rather, they are processed by a recursive call to B<Config::Scoped>. Subclass implementers may need to be aware of this.

=head2 Warnings

B<Config::Scoped> can check for 5 problems with config files

=over 4

=item *

duplicate declaration names

=item *

duplicate parameter definitions

=item *

duplicate macro definitions

=item *

insecure config file permissions

=item *

invalid config cache digests

=back

The API refers to these as "warnings", but they are actually errors, and if they occur, the parse fails and throws an exception. For consistency with the API, we'll use the term "warning" in the POD.

The five warnings are identified by five predefined B<warning names>

=over 4

=item *

B<declaration>

=item *

B<parameter>

=item *

B<macro>

=item *

B<permissions>

=item *

B<digests>

=back

The B<permissions> check requires that the config file

=over 4

=item *

be owned by root or the real UID of the running process AND

=item *

have no group or world write permissions

=back

These restrictions help prevent an attacker from subverting a program by altering its config files.


The B<store_cache> method computes MD5 checksums for the config file and all included files. These checksums are stored with the cached configuration.

The B<retrieve_cache> method recomputes the checksums of the files and compares them to the stored values.

The B<digests> check requires that the checksums agree. This helps prevent programs from relying on stale configuration caches.

All warnings are enabled by default.

Warnings can be disabled by passing the B<warning> key to the constructor or with the B<set_warnings> method.

Warnings can also be controlled with the B<%warnings> directive, which has the form

B<%warnings> [B<name>] B<off>|B<on>

A B<%warnings> directive applies to the B<name>d warning, or to all warnings, if B<name> is omitted.

B<%warnings> directives allow warnings to be turned on and off as necessary throughout the config file. A B<%warnings> directive may appear

=over 4

=item *

at file scope

=item *

within anonymous blocks

=item *

within declaration blocks

=item *

within hash blocks

=back

Each B<%warnings> directive is lexically scoped to its enclosing file or block.

Example

  legs = 4
  cat  {}
  dog  {}
  bird
  {
      legs = 2
  }

fails with a duplicate parameter warning, but

  legs = 4
  cat  {}
  dog  {}
  bird
  {
      %warnings parameter off;
      legs = 2
  }

successfully parses to

    $cfg_hash = {
        cat  => { legs => 4 },
        dog  => { legs => 4 },
        bird => { legs => 2 },
      }


=head1 Best practices

As with all things Perl, there's more than one way to write configuration files. Here are some suggestions for writing config files that are concise, readable, and maintainable.

=head2 Perl data

B<Config::Scoped> accepts most Perl data syntax. This allows Perl data to pulled into config files largely unaltered

  foo
  {
     a = 1;
     b = [ 'red', 'green', 'blue' ];
     c = { x => 5,
           y => 6 };
  }

However, B<Config::Scoped> doesn't require as much punctuation as Perl, and config files written from scratch will be cleaner without it

  foo
  {
     a = 1
     b = [ red green blue ]
     c = { x => 5
           y => 6 }
  }


=head2 Anonymous blocks

Don't use anonymous blocks unless you need to restrict the scope of something. In particular, there is no need for a top-level anonymous block around the whole config file

  {             # unnecessary
      foo { }
  }

=head2 Inheritance

Parameters that are outside of a declaration are inherited by B<all> following declarations in their scope. Don't do this unless you mean it

  wheels = 4
  car
  {
      # OK
  }
  cat
  {
      # I can haz weelz?
  }


=head2 Blocks, blocks, we got blocks...

B<Config::Scoped> has four different kinds of blocks

=over 4

=item *

anonymous

=item *

declaration

=item *

eval

=item *

hash

=back

They all look the same, but they aren't, and they have different rules and restrictions. See L</CONFIG FILE FORMAT> for descriptions of each.

=head2 Macros

Macros are evil, and B<Config::Scoped> macros are specially evil, because

=over 4

=item *

they don't respect token boundaries

=item *

where multiple substitutions are possible, the substitution order is undefined

=item *

substituted text may or may not be rescanned for further substitutions

=back

Caveat scriptor.


=head1 SUBCLASSING

B<Config::Scoped> has no formally defined subclass interface. Here are some guidelines for writing subclasses. Implementers who override (or redefine) base class methods may need to read the B<Config::Scoped> sources for more information.

Arbitrary

  $your_key => $value

pairs may be passed to the B<Config::Scoped> constructor. They will be stored in the B<< $cs->{local} >> hashref, and methods may access them with code like

  $cs->{local}{$your_key}

To avoid conflict with existing keys in the B<local> hash, consider distinguishing your keys with a unique prefix.

Arbitrary warning names may be defined, set with B<new> and B<set_warnings>, used in B<%warnings> directives, and tested with B<warnings_on>. Methods can call B<warnings_on> to find out whether a warning is currently enabled.

All methods throw exceptions (B<die>) on error. The exception object should be a subclass of B<Config::Scoped::Error>. You can use one of the classes defined in B<Config::Scoped::Error>, or you can derive your own. This code

    Config::Scoped::Error->throw(
        -file => $cs->_get_file(%args),
        -line => $cs->_get_line(%args),
        -text => $message,
    );

will generate an error message that reports the location in the config file where the error was detected, rather than a location in Perl code.

B<Config::Scoped> performs validation checks on the elements of configuration files (declarations, parameters, macros, etc). Here are the interfaces to the validation methods. Subclasses can override these methods to modify or extend the validation checks.

=over 4

=item B<< $macro_value = $cs->macro_validate>(name => $name, value => $value) >>

Called for each B<%macro> directive.

Receives the B<$name> and B<$value> from the directive. The returned B<$macro_value> becomes the actual value of the macro.

If the macro is invalid, throws a B<Config::Scoped::Error::Validate::Macro> exception.


=item B<< $param_value = $cs->parameter_validate>(name => $name, value => $value) >>

Called for each parameter definition.

Receives the B<$name> and B<$value> from the definition. The returned B<$param_value> becomes the actual value of the parameter.

If the parameter is invalid, throws a B<Config::Scoped::Error::Validate::Parameter> exception.


=item B<< $cs->declaration_validate(name => $name, value => $value, tail => $tail) >>

Called for each declaration.

B<$name> is an array ref giving the chain of names for the declaration block. B<$value> is a hash ref containing all the parameters in the declaration block. B<$tail> is a hash ref containing all the parameters in any previously defined declaration with the same name(s).

For example, the declaration

  foo bar baz { a=1 b=2 }

leads to the call

  $cs->declaration_validate(name  => [ qw(foo bar baz) ],
                                value => { a => '1', b => '2' },
                                tail  => $cs->{local}{config}{foo}{bar}{baz});

The method can test %$tail to discover if there is an existing, non-empty declaration with the same name(s).

The method has no return value. However, the method can alter the contents of %$value. Upon return, the parameters in %$value become the actual contents of the declaration block.

If the declaration is invalid, throws a B<Config::Scoped::Error::Validate::Declaration> exception.


=item B<< $cs->permissions_validate(file => $file, handle => $handle) >>

Called for the config file, each included file, and each retrieved cache file. One of B<$file> or B<$handle> must be non-null.

Throws a B<Config::Scoped::Error::Validate::Permissions> exception if the file is not safe to read.


=back


=head1 SEE ALSO

=over 4

=item *

B<Error>

=item *

B<Safe>

=item *

B<Config::Scoped::Error>

=item *

B<Parse::RecDescent>

=item *

L<perlop/Quote and Quote-like Operators>

=back

=head1 TODO

=over 4

=item Tests

Still more tests needed.

=back

=head1 BUGS

If you find parser bugs, please send the stripped down config file and
additional version information to the author.

=head1 CREDITS

POD by Steven W. McDougall E<lt>swmcd@world.std.comE<gt>

=head1 AUTHOR

Karl Gaissmaier E<lt>karl.gaissmaier at uni-ulm.deE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2004-2012 by Karl Gaissmaier

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

# vim: sw=4 ft=pod