| 1 | package Tkx::MegaConfig; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | our $VERSION = '1.10'; | ||
| 5 | |||
| 6 | my %spec; | ||
| 7 | |||
| 8 | sub _Config { | ||
| 9 | my $class = shift; | ||
| 10 | while (@_) { | ||
| 11 | my($opt, $spec) = splice(@_, 0, 2); | ||
| 12 | $spec{$class}{$opt} = $spec; | ||
| 13 | } | ||
| 14 | } | ||
| 15 | |||
| 16 | sub m_configure { | ||
| 17 | my $self = shift; | ||
| 18 | my @rest; | ||
| 19 | while (@_) { | ||
| 20 | my($opt, $val) = splice(@_, 0, 2); | ||
| 21 | my $spec = $spec{ref($self)}{$opt} || $spec{ref($self)}{DEFAULT}; | ||
| 22 | unless ($spec) { | ||
| 23 | push(@rest, $opt => $val); | ||
| 24 | next; | ||
| 25 | } | ||
| 26 | |||
| 27 | my $where = $spec->[0]; | ||
| 28 | my @where_args; | ||
| 29 | if (ref($where) eq "ARRAY") { | ||
| 30 | ($where, @where_args) = @$where; | ||
| 31 | } | ||
| 32 | |||
| 33 | if ($where =~ s/^\.//) { | ||
| 34 | my $fwd_opt = $where_args[0] || $opt; | ||
| 35 | if ($where eq "") { | ||
| 36 | $self->Tkx::widget::m_configure($fwd_opt, $val); | ||
| 37 | next; | ||
| 38 | } | ||
| 39 | if ($where eq "*") { | ||
| 40 | for my $kid ($self->_kids) { | ||
| 41 | $kid->m_configure($fwd_opt, $val); | ||
| 42 | } | ||
| 43 | next; | ||
| 44 | } | ||
| 45 | $self->_kid($where)->m_configure($fwd_opt, $val); | ||
| 46 | next; | ||
| 47 | } | ||
| 48 | |||
| 49 | if ($where eq "METHOD") { | ||
| 50 | my $method = $where_args[0] || "_config_" . substr($opt, 1); | ||
| 51 | $self->$method($val); | ||
| 52 | next; | ||
| 53 | } | ||
| 54 | |||
| 55 | if ($where eq "PASSIVE") { | ||
| 56 | $self->_data->{$opt} = $val; | ||
| 57 | next; | ||
| 58 | } | ||
| 59 | |||
| 60 | die; | ||
| 61 | } | ||
| 62 | |||
| 63 | $self->Tkx::widget::m_configure(@rest) if @rest; # XXX want NEXT instead | ||
| 64 | } | ||
| 65 | |||
| 66 | sub m_cget { | ||
| 67 | my($self, $opt) = @_; | ||
| 68 | my $spec = $spec{ref($self)}{$opt} || $spec{ref($self)}{DEFAULT}; | ||
| 69 | return $self->Tkx::widget::m_cget($opt) unless $spec; # XXX want NEXT instead | ||
| 70 | |||
| 71 | my $where = $spec->[0]; | ||
| 72 | my @where_args; | ||
| 73 | if (ref($where) eq "ARRAY") { | ||
| 74 | ($where, @where_args) = @$where; | ||
| 75 | } | ||
| 76 | |||
| 77 | if ($where =~ s/^\.//) { | ||
| 78 | my $fwd_opt = $where_args[0] || $opt; | ||
| 79 | return $self->Tkx::widget::m_cget($fwd_opt) if $where eq ""; | ||
| 80 | return ($self->_kids)[0]->m_cget($fwd_opt) if $where eq "*"; | ||
| 81 | return $self->_kid($where)->m_cget($fwd_opt); | ||
| 82 | } | ||
| 83 | |||
| 84 | if ($where eq "METHOD") { | ||
| 85 | my $method = $where_args[0] || "_config_" .substr($opt, 1); | ||
| 86 | return $self->$method; | ||
| 87 | } | ||
| 88 | |||
| 89 | if ($where eq "PASSIVE") { | ||
| 90 | return $self->_data->{$opt}; | ||
| 91 | } | ||
| 92 | |||
| 93 | die; | ||
| 94 | } | ||
| 95 | |||
| 96 | 1; | ||
| 97 | |||
| 98 | __END__ |