| 1 | package FindApp::Object::State::Group::State; | ||
| 2 | |||
| 3 | use v5.10; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use mro "c3"; | ||
| 7 | |||
| 8 | use FindApp::Vars qw(:all); | ||
| 9 | use FindApp::Utils qw(:all); | ||
| 10 | |||
| 11 | ################################################################# | ||
| 12 | |||
| 13 | sub dir_field ( _ ) ; | ||
| 14 | sub dir_fields ( ) ; | ||
| 15 | sub dir_types ( ) ; | ||
| 16 | sub field_map ( & @ ) ; | ||
| 17 | sub type_map ( & @ ) ; | ||
| 18 | |||
| 19 | ################################################################# | ||
| 20 | |||
| 21 | sub dir_types() { | ||
| 22 | return qw(allowed wanted found); | ||
| 23 | } | ||
| 24 | |||
| 25 | sub dir_field(_) { | ||
| 26 | my($type) = @_; | ||
| 27 | no strict "refs"; | ||
| 28 | return &{uc $type}; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub type_map(&@) { | ||
| 32 | my $code = shift; | ||
| 33 | return map { &$code } +dir_types, @_; | ||
| 34 | } | ||
| 35 | |||
| 36 | sub dir_fields() { | ||
| 37 | my $fields = [ type_map{dir_field} ]; | ||
| 38 | return @$fields; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub field_map(&@) { | ||
| 42 | my $code = shift; | ||
| 43 | return map { &$code } +dir_fields, @_; | ||
| 44 | } | ||
| 45 | |||
| 46 | use namespace::clean; | ||
| 47 | |||
| 48 | ################################################################ | ||
| 49 | |||
| 50 | use pluskeys qw{ | ||
| 51 | NAME | ||
| 52 | EXPORTED | ||
| 53 | } => type_map{uc}; | ||
| 54 | |||
| 55 | sub unexported { | ||
| 56 | bad_args(!@_ || @_ > 2); | ||
| 57 | my($self, $value) = @_; | ||
| 58 | if ($value) { | ||
| 59 | $$self{+EXPORTED} = 0; | ||
| 60 | } | ||
| 61 | return !$$self{+EXPORTED}; | ||
| 62 | } | ||
| 63 | |||
| 64 | sub have_exported { | ||
| 65 | good_args(@_ == 1); | ||
| 66 | my $self = shift; | ||
| 67 | return $$self{+EXPORTED}; | ||
| 68 | } | ||
| 69 | |||
| 70 | sub bump_exports { | ||
| 71 | good_args(@_ == 1); | ||
| 72 | my $self = shift; | ||
| 73 | return ++$$self{+EXPORTED}; | ||
| 74 | } | ||
| 75 | |||
| 76 | sub exported { | ||
| 77 | bad_args(@_ > 2); | ||
| 78 | my $self = shift; | ||
| 79 | use warnings FATAL => qw(numeric uninitialized); | ||
| 80 | $$self{+EXPORTED} += shift if @_; | ||
| 81 | $$self{+EXPORTED}; | ||
| 82 | } | ||
| 83 | |||
| 84 | sub name { | ||
| 85 | bad_args(@_ > 2); | ||
| 86 | my $self = shift; | ||
| 87 | return $$self{+NAME} unless @_; | ||
| 88 | my $old_name = $$self{+NAME}; | ||
| 89 | my $new_name = shift; | ||
| 90 | for ($new_name) { | ||
| 91 | defined || die "name cannot be undef"; | ||
| 92 | length || die "name cannot be zero length"; | ||
| 93 | !ref || die "name cannot be a reference"; | ||
| 94 | !/\0/ || die "name cannot contain NUL characters"; | ||
| 95 | } | ||
| 96 | $$self{+NAME} = $new_name; | ||
| 97 | return $old_name; | ||
| 98 | } | ||
| 99 | |||
| 100 | sub access_AWF_subdir { | ||
| 101 | my($self, $dirs, @values) = @_; | ||
| 102 | $dirs->set(@values) if @values; | ||
| 103 | if (wantarray) { return $dirs->get } | ||
| 104 | elsif (defined wantarray) { return $dirs } | ||
| 105 | else { return } | ||
| 106 | } | ||
| 107 | |||
| 108 | BEGIN { | ||
| 109 | my %ACCESSOR = type_map { $_ => dir_field }; | ||
| 110 | # BUILD: allowed, wanted, found | ||
| 111 | while (my($TYPE, $FIELD) = each %ACCESSOR) { | ||
| 112 | function $TYPE => sub { &ENTER_TRACE_2; | ||
| 113 | my $self = shift; | ||
| 114 | $self->access_AWF_subdir($$self{$FIELD}, @_); | ||
| 115 | }; | ||
| 116 | } | ||
| 117 | } | ||
| 118 | |||
| 119 | 1; | ||
| 120 | |||
| 121 | =encoding utf8 | ||
| 122 | |||
| 123 | =head1 NAME | ||
| 124 | |||
| 125 | FindApp::Object::State::Group::Object::State - FIXME | ||
| 126 | |||
| 127 | =head1 SYNOPSIS | ||
| 128 | |||
| 129 | use FindApp::Object::State::Group::Object::State; | ||
| 130 | |||
| 131 | =head1 DESCRIPTION | ||
| 132 | |||
| 133 | =head2 Pluskey Attributes | ||
| 134 | |||
| 135 | These are always private; use the methods insteads. | ||
| 136 | |||
| 137 | =over | ||
| 138 | |||
| 139 | =item ALLOWED | ||
| 140 | |||
| 141 | =item EXPORTED | ||
| 142 | |||
| 143 | =item FOUND | ||
| 144 | |||
| 145 | =item NAME | ||
| 146 | |||
| 147 | =item WANTED | ||
| 148 | |||
| 149 | =back | ||
| 150 | |||
| 151 | =head2 Public Methods | ||
| 152 | |||
| 153 | =over | ||
| 154 | |||
| 155 | =item ALLOWED | ||
| 156 | |||
| 157 | =item FOUND | ||
| 158 | |||
| 159 | =item WANTED | ||
| 160 | |||
| 161 | =item access_AWF_subdir | ||
| 162 | |||
| 163 | =item allowed | ||
| 164 | |||
| 165 | =item bump_exports | ||
| 166 | |||
| 167 | =item exported | ||
| 168 | |||
| 169 | =item found | ||
| 170 | |||
| 171 | =item have_exported | ||
| 172 | |||
| 173 | =item name | ||
| 174 | |||
| 175 | =item unexported | ||
| 176 | |||
| 177 | =item wanted | ||
| 178 | |||
| 179 | =item FIXME | ||
| 180 | |||
| 181 | =back | ||
| 182 | |||
| 183 | =head2 Exports | ||
| 184 | |||
| 185 | =over | ||
| 186 | |||
| 187 | =item FIXME | ||
| 188 | |||
| 189 | =back | ||
| 190 | |||
| 191 | =head1 EXAMPLES | ||
| 192 | |||
| 193 | =head1 ENVIRONMENT | ||
| 194 | |||
| 195 | =head1 SEE ALSO | ||
| 196 | |||
| 197 | =over | ||
| 198 | |||
| 199 | =item L<FindApp> | ||
| 200 | |||
| 201 | =back | ||
| 202 | |||
| 203 | =head1 CAVEATS AND PROVISOS | ||
| 204 | |||
| 205 | =head1 BUGS AND LIMITATIONS | ||
| 206 | |||
| 207 | =head1 HISTORY | ||
| 208 | |||
| 209 | =head1 AUTHOR | ||
| 210 | |||
| 211 | Tom Christiansen << <tchrist@perl.com> >> | ||
| 212 | |||
| 213 | =head1 LICENCE AND COPYRIGHT | ||
| 214 | |||
| 215 | Copyright (c) 2016, Tom Christiansen C<< <tchrist@perl.com> >>. | ||
| 216 | All Rights Reserved. | ||
| 217 | |||
| 218 | This module is free software; you can redistribute it and/or | ||
| 219 | modify it under the same terms as Perl itself. See L<perlartistic>. | ||
| 220 | |||
| 221 | =cut | ||
| 222 |