Skip to content

Commit

Permalink
Item13897: Converted toold/configure
Browse files Browse the repository at this point in the history
Tested with -save only so far.

- configure doesn't use setlib.cfg.

- Foswiki::Configure::Item::ATTRSPEC converted from constant to a object
attribute. Method _establishATTRSPEC must be overriden by a subclass to
provide defaults.
  • Loading branch information
vrurg committed Jul 15, 2016
1 parent b613253 commit 2cc6e72
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 120 deletions.
47 changes: 31 additions & 16 deletions core/lib/Foswiki/Configure/Item.pm
Expand Up @@ -32,23 +32,20 @@ use Moo;
use namespace::clean;
extends qw(Foswiki::Object);

# Schema for dynamic attributes
use constant ATTRSPEC => {};

has attrs => (
is => 'rw',
is => 'rw',
lazy => 1,
trigger => sub { $_[0]->_checkOpts; },
isa => Foswiki::Object::isaHASH( 'attrs', noUndef => 1, ),
required => 1,
);

# Schema for dynamic attributes
has ATTRSPEC => (
is => 'ro',
lazy => 1,
clearer => 1,
default => sub { {} },
trigger => sub {
my $this = shift;
my ($newAttrs) = @_;
if ( $newAttrs->{opts} ) {
$this->_parseOptions( $newAttrs->{opts} );
delete $this->attrs->{opts};
}
},
isa => Foswiki::Object::isaHASH( 'attrs', noUndef => 1, ),
builder => '_establishATTRSPEC',
isa => Foswiki::Object::isaHASH( 'ATTRSPEC', noUndef => 1, ),
);

=begin TML
Expand All @@ -66,15 +63,33 @@ around BUILDARGS => sub {
$params{desc} //= '';

foreach my $attr ( keys %params ) {
$params{attrs}{$attr} = $params{$attr};
unless ( $class->can($attr) ) {
$params{attrs}{$attr} = $params{$attr};
delete $params{$attr};
}
}

return $orig->( $class, %params );
};

sub BUILD {
my $this = shift;

$this->_checkOpts;
}

sub _checkOpts {
my $this = shift;
if ( $this->attrs->{opts} ) {
$this->_parseOptions( $this->attrs->{opts} );
delete $this->attrs->{opts};
}
}

sub _establishATTRSPEC {
return {};
}

sub stringify {
my $this = shift;
my $s = Data::Dumper->Dump( [ $this->TO_JSON() ] );
Expand Down
17 changes: 9 additions & 8 deletions core/lib/Foswiki/Configure/LoadSpec.pm
Expand Up @@ -3,6 +3,7 @@
# Inner class that represents section headings temporarily during the
# parse. They are expanded to section blocks at the end.
package SectionMarker;
use v5.14;
use Moo;
extends qw(Foswiki::Configure::Item);

Expand All @@ -14,6 +15,7 @@ sub BUILD { my $this = shift; $this->Depth( $this->Depth + 1 ); }
sub getValueObject { return; }

package Foswiki::Configure::LoadSpec;
use v5.14;

=begin TML
Expand Down Expand Up @@ -73,13 +75,12 @@ use warnings;
use Assert;
use Try::Tiny;

use Foswiki::Configure::Section ();
use Foswiki::Configure::Value ();
use Foswiki::Configure::Item ();
use Foswiki::Configure::Load ();
use Foswiki::Configure::FileUtil ();
use Foswiki::Configure::Pluggable ();
use Foswiki::Configure::Reporter ();
use Foswiki::Configure::Section;
use Foswiki::Configure::Value;
use Foswiki::Configure::Load;
use Foswiki::Configure::FileUtil;
use Foswiki::Configure::Pluggable;
use Foswiki::Configure::Reporter;

our $TRUE = 1; # Required for checking default value syntax
our $FALSE = 0;
Expand Down Expand Up @@ -308,7 +309,7 @@ sub parse {
$open = Foswiki::Configure::Value->new(
typename => $type,
opts => $opts,
defined_at => [ $file, $. ]
defined_at => [ $file, $. ],
);
$reporter->NOTE( "\tOpened " . $open->attrs->{typename} )
if TRACE;
Expand Down
20 changes: 10 additions & 10 deletions core/lib/Foswiki/Configure/Package.pm
Expand Up @@ -510,11 +510,11 @@ HERE
# Add it to the $spec
$spec->addChild(
Foswiki::Configure::Value->new(
'BOOLEAN',
LABEL => $plu,
keys => "{Plugins}{$plu}{Enabled}",
CHECKER => 'PLUGIN_MODULE',
default => '1'
typename => 'BOOLEAN',
LABEL => $plu,
keys => "{Plugins}{$plu}{Enabled}",
CHECKER => 'PLUGIN_MODULE',
default => '1'
)
);
}
Expand All @@ -529,11 +529,11 @@ HERE
# Add it to the $spec
$spec->addChild(
Foswiki::Configure::Value->new(
'STRING',
LABEL => "$plu Module",
keys => "{Plugins}{$plu}{Module}",
CHECKER => 'PLUGIN_MODULE',
default => 'Foswiki::Plugins::$plu'
typename => 'STRING',
LABEL => "$plu Module",
keys => "{Plugins}{$plu}{Module}",
CHECKER => 'PLUGIN_MODULE',
default => 'Foswiki::Plugins::$plu'
)
);
}
Expand Down
14 changes: 8 additions & 6 deletions core/lib/Foswiki/Configure/Section.pm
Expand Up @@ -18,12 +18,6 @@ use Moo;
use namespace::clean;
extends qw(Foswiki::Configure::Item);

# Attributes legal on a section header
use constant ATTRSPEC => {
EXPERT => {},
SORTED => {}
};

=begin TML
---++ ClassMethod new(@opts)
Expand All @@ -45,6 +39,14 @@ around BUILDARGS => sub {
return $orig->( $class, %params );
};

# Attributes legal on a section header
around _establishATTRSPEC => sub {
return {
EXPERT => {},
SORTED => {}
};
};

=begin TML
---++ ObjectMethod addChild($child)
Expand Down
44 changes: 22 additions & 22 deletions core/lib/Foswiki/Configure/Value.pm
Expand Up @@ -50,8 +50,6 @@ Processes are used to parse 'FEEDBACK' and 'CHECK' values.
=cut

package Foswiki::Configure::Value;

use strict;
use v5.14;

use Data::Dumper ();
Expand All @@ -65,26 +63,6 @@ use Moo;
use namespace::clean;
extends qw(Foswiki::Configure::Item);

# Options valid in a .spec for a leaf value
use constant ATTRSPEC => {
CHECK => { handler => '_CHECK' },
CHECKER => {},
CHECK_ON_CHANGE => {},
DISPLAY_IF => { openclose => 1 },
ENABLE_IF => { openclose => 1 },
EXPERT => {},
FEEDBACK => { handler => '_FEEDBACK' },
HIDDEN => {},
MULTIPLE => {}, # Allow multiple select
SPELLCHECK => {},
LABEL => {},
ONSAVE => {}, # Call Checker->onSave() when set.

# Rename single character options (legacy)
H => 'HIDDEN',
M => { handler => '_MANDATORY' }
};

# Legal options for a CHECK. The number indicates the number of expected
# parameters; -1 means '0 or more'
our %CHECK_options = (
Expand Down Expand Up @@ -136,6 +114,28 @@ sub BUILD {
$this->attrs->{CHECK}->{emptyok} //= 1; # required for legacy
}

# Options valid in a .spec for a leaf value
around _establishATTRSPEC => sub {
return {
CHECK => { handler => '_CHECK' },
CHECKER => {},
CHECK_ON_CHANGE => {},
DISPLAY_IF => { openclose => 1 },
ENABLE_IF => { openclose => 1 },
EXPERT => {},
FEEDBACK => { handler => '_FEEDBACK' },
HIDDEN => {},
MULTIPLE => {}, # Allow multiple select
SPELLCHECK => {},
LABEL => {},
ONSAVE => {}, # Call Checker->onSave() when set.

# Rename single character options (legacy)
H => 'HIDDEN',
M => { handler => '_MANDATORY' },
};
};

# Return true if this value is one of the preformatted types. Values for
# these types transfer verbatim from the UI to the LocalSite.cfg
sub isFormattedType {
Expand Down

0 comments on commit 2cc6e72

Please sign in to comment.