| 1 | package Config::Maker::Schema; | ||||||||||
| 2 | |||||||||||
| 3 | 9 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 9 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 9 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 9 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 9 | ▶ | use Config::Maker; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 9 | ▶ | use Config::Maker::Type; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 105 | ▶ | sub type { | ||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 13 | 105 | Config::Maker::Type->new(@_); | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | # Top-level element "schema" | ||||||||||
| 17 | |||||||||||
| 18 | 9 | my $schema = type( | |||||||||
| 19 | name => 'schema', | ||||||||||
| 20 | format => ['anon_group'], | ||||||||||
| 21 | contexts => [any => '/', any => '*'], | ||||||||||
| 22 | actions => [\&process_schema], | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | # Global 'type' element | ||||||||||
| 26 | |||||||||||
| 27 | 9 | my $type = type( | |||||||||
| 28 | name => 'type', | ||||||||||
| 29 | format => [named_group => ['identifier']], | ||||||||||
| 30 | contexts => [any => $schema], | ||||||||||
| 31 | actions => [\&process_type], | ||||||||||
| 32 | ); | ||||||||||
| 33 | |||||||||||
| 34 | # Local 'type' element and 'contains' element | ||||||||||
| 35 | |||||||||||
| 36 | 9 | my $itype = type( | |||||||||
| 37 | name => 'type', | ||||||||||
| 38 | format => [named_group => [pair => ['identifier'], ['identifier']]], | ||||||||||
| 39 | contexts => [any => $type], | ||||||||||
| 40 | actions => [\&process_itype], | ||||||||||
| 41 | ); | ||||||||||
| 42 | 9 | $itype->add(any => $itype); | |||||||||
| 43 | |||||||||||
| 44 | 9 | my $contains = type( | |||||||||
| 45 | name => 'contains', | ||||||||||
| 46 | format => [simple => [pair => ['identifier'], ['identifier']]], | ||||||||||
| 47 | contexts => [any => $type, any => $itype], | ||||||||||
| 48 | ); | ||||||||||
| 49 | |||||||||||
| 50 | # Format elements | ||||||||||
| 51 | |||||||||||
| 52 | 9 | my $simple = type( | |||||||||
| 53 | name => 'simple', | ||||||||||
| 54 | format => [simple => [nested_list => 'string']], | ||||||||||
| 55 | contexts => [opt => $type, opt => $itype], | ||||||||||
| 56 | ); | ||||||||||
| 57 | |||||||||||
| 58 | 9 | my $anon_group = type( | |||||||||
| 59 | name => 'anon_group', | ||||||||||
| 60 | format => [simple => ['void']], | ||||||||||
| 61 | contexts => [opt => $type, opt => $itype], | ||||||||||
| 62 | ); | ||||||||||
| 63 | |||||||||||
| 64 | 9 | my $named_group = type( | |||||||||
| 65 | name => 'named_group', | ||||||||||
| 66 | format => [simple => [nested_list => 'string']], | ||||||||||
| 67 | contexts => [opt => $type, opt => $itype], | ||||||||||
| 68 | ); | ||||||||||
| 69 | 9 | $type->addchecks(one => 'simple|anon_group|named_group'); | |||||||||
| 70 | 9 | $itype->addchecks(one => 'simple|anon_group|named_group'); | |||||||||
| 71 | |||||||||||
| 72 | # "toplevel" modifier | ||||||||||
| 73 | 9 | my $top_level = type( | |||||||||
| 74 | name => 'toplevel', | ||||||||||
| 75 | format => [simple => ['void']], | ||||||||||
| 76 | contexts => [opt => $type, opt => $itype], | ||||||||||
| 77 | ); | ||||||||||
| 78 | |||||||||||
| 79 | # Action elements | ||||||||||
| 80 | |||||||||||
| 81 | 9 | my $action = type( | |||||||||
| 82 | name => 'action', | ||||||||||
| 83 | format => [simple => ['perlcode']], | ||||||||||
| 84 | contexts => [any => $type, any => $itype], | ||||||||||
| 85 | ); | ||||||||||
| 86 | |||||||||||
| 87 | # Processing schema. Ugh! | ||||||||||
| 88 | |||||||||||
| 89 | 24 | ▶ | sub _get_format { | ||||||||
|
Subroutine
_get_format: called CC=1 SCAR=0.0
| |||||||||||
| 90 | 24 | my ($fmt) = $_->get1('simple|anon_group|named_group'); | |||||||||
| 91 | 24 | [ "$fmt->{-type}", $fmt->{-value} ]; | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 24 | ▶ | sub _do_type { | ||||||||
|
Subroutine
_do_type: called CC=2 SCAR=7.0
| |||||||||||
| 95 | 24 | $_{format} = _get_format(); | |||||||||
| 96 | $_{children} = [ map { | ||||||||||
| 97 | 24 | $_->{-value}->[0], $_->{-data} | |||||||||
| 98 | 11 | } $_->get('type') ]; | |||||||||
| 99 | 24 | ▶ | push @{$_{contexts}}, any => '/' if $_->get('toplevel'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | $_{actions} = [ map { | ||||||||||
| 101 | 0 | Config::Maker::exe("sub $_->{-value}"); | |||||||||
| 102 | } $_->get('action') ]; | ||||||||||
| 103 | 24 | $_->{-data} = type(\%_); | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | sub process_itype | ||||||||||
| 107 | 11 | ▶ | { | ||||||||
|
Subroutine
process_itype: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 108 | 11 | local ($_) = @_; | |||||||||
| 109 | 11 | local %_; | |||||||||
| 110 | 11 | $_{name} = $_[0]->{-value}->[1]; | |||||||||
| 111 | 11 | $_{contexts} = []; | |||||||||
| 112 | 11 | &_do_type; | |||||||||
| 113 | } | ||||||||||
| 114 | |||||||||||
| 115 | sub process_type | ||||||||||
| 116 | 13 | ▶ | { | ||||||||
|
Subroutine
process_type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 117 | 13 | local ($_) = @_; | |||||||||
| 118 | 13 | local %_; | |||||||||
| 119 | 13 | $_{name} = $_[0]->{-value}; | |||||||||
| 120 | 13 | $_{contexts} = [any => '*'], | |||||||||
| 121 | &_do_type; | ||||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | sub process_schema | ||||||||||
| 125 | 6 | ▶ | { | ||||||||
|
Subroutine
process_schema: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 126 | 6 | local ($_) = @_; | |||||||||
| 127 | # Types are already processed! | ||||||||||
| 128 | # But now we need to process cross-refs... | ||||||||||
| 129 | 6 | for my $type ($_->get('**/type')) { | |||||||||
| 130 | 24 | DBG "Type $type->{-data}..."; | |||||||||
| 131 | 24 | for my $cont ($type->get('contains')) { | |||||||||
| 132 | 5 | DBG "Contains $cont->{-value}[0] $cont->{-value}[1]"; | |||||||||
| 133 | 5 | $type->{-data}->add(@{$cont->{-value}}) | |||||||||
| 134 | } | ||||||||||
| 135 | } | ||||||||||
| 136 | } | ||||||||||
| 137 | |||||||||||
| 138 | 9 | 1; | |||||||||
| 139 | |||||||||||
| 140 | __END__ | ||||||||||