Skip to content

Commit

Permalink
Item9275: find a nice balance; let the developer know there's a probl…
Browse files Browse the repository at this point in the history
…em, without banjaxing configure. Also removed redundant TAGS module, which doesn't even compile any more and isn't in MANIFEST

git-svn-id: http://svn.foswiki.org/trunk@8095 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Jul 9, 2010
1 parent 9e11f91 commit 7e60bae
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 89 deletions.
25 changes: 16 additions & 9 deletions core/lib/Foswiki/Configure/Type.pm
Expand Up @@ -20,6 +20,8 @@ use warnings;

use CGI qw( :any );

use Foswiki::Configure::Types::UNKNOWN;

our %knownTypes;

sub new {
Expand All @@ -30,29 +32,34 @@ sub new {

=begin TML
---++ StaticMethod load(id) -> $typeObject
---++ StaticMethod load($id, $keys) -> $typeObject
Load the named type object
* $id - the type name e.g. SELECTCLASS
* $keys - the item the type is being loaded for. Only used to
generate errors.
=cut

sub load {
my $id = shift;
my ($id, $keys) = @_;
my $typer = $knownTypes{$id};
unless ($typer) {
my $failinfo;
my $typeClass = 'Foswiki::Configure::Types::' . $id;
eval "use $typeClass";
#TODO: rather than making Configure crash and unusable
#load the UNKNOWN type - I wish I knew how to also raise an error (maybe UNKNOWN's renderer shoudl always do so?
#Carp::confess "Could not load type $id: $@" if ($@);
if ($@) {
if ($@) {
$failinfo = "**$id** could not be 'use'd";
print STDERR "$failinfo: $@";
$typeClass = 'Foswiki::Configure::Types::UNKNOWN';
eval "use $typeClass";
}
}
$typer = $typeClass->new($id);
unless ($typer) {
# unknown type - give it default behaviours
$typer = new Foswiki::Configure::Type($id);
# unknown type - give it UNKNOWN behaviours
$failinfo = "**$id** loaded, but the 'new' method returned undef";
$typer = new Foswiki::Configure::Types::UNKNOWN($id);
}
$typer->{failinfo} = $failinfo if defined $failinfo;
$knownTypes{$id} = $typer;
}
return $typer;
Expand Down
8 changes: 8 additions & 0 deletions core/lib/Foswiki/Configure/Types/UNKNOWN.pm
Expand Up @@ -17,6 +17,14 @@ sub new {
return bless( { name => 'UNKNOWN' }, $class );
}

sub prompt {
my $this = shift;
return $this->SUPER::prompt(@_)
. '<br /><span class="foswikiAlert"> .spec ERROR! TYPE '
. ($this->{failinfo} || 'UNKNOWN')
.'</span>';
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Expand Down
73 changes: 0 additions & 73 deletions core/lib/Foswiki/Configure/UIs/TAGS.pm

This file was deleted.

14 changes: 8 additions & 6 deletions core/lib/Foswiki/Configure/Value.pm
Expand Up @@ -37,10 +37,11 @@ our $VALUE_TYPE = {
---++ ClassMethod new($typename, %params)
* =$typename= e.g 'STRING', name of one of the Foswiki::Configure::Types
Defaults to 'UNKNOWN' if not given ('', 0 or undef).
%params may include:
* parent node
* keys e.g {Garden}{Flowers}',
* keys e.g {Garden}{Flowers}
* expertsOnly boolean
* opts options
Constructor. The opts are attributes, and by convention may
Expand All @@ -50,15 +51,18 @@ be a number (for a string length), a comma separated list of values
=cut

sub new {
my ($class, $typename) = @_;
my $class = shift;
my $typename = shift;

my $this =
bless( $class->SUPER::new('Foswiki::Configure::UIs::Value'), $class );

$this->{typename} = ($typename || 'UNKNOWN');
$this->{typename} = ($typename || 'UNKNOWN');
$this->{keys} = '';
$this->{opts} = '';
$this->{expertsOnly} = 0;

# Transfer remaining params into the object
$this->set(@_);

if ( defined $this->{opts} ) {
Expand Down Expand Up @@ -96,7 +100,7 @@ sub getType {
my $this = shift;
unless ( $this->{type} ) {
$this->{type} =
Foswiki::Configure::Type::load( $this->{typename} || 'UNKNOWN' );
Foswiki::Configure::Type::load( $this->{typename}, $this->{keys} );
}
return $this->{type};
}
Expand Down Expand Up @@ -153,8 +157,6 @@ sub asString {

$value ||= '';

return $value if !defined $this->{typename};

if ( $this->{typename} eq 'PERL'
|| $this->{typename} eq 'HASH'
|| $this->{typename} eq 'ARRAY' )
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Configure/Valuer.pm
Expand Up @@ -110,7 +110,7 @@ sub loadCGIParams {
my $typename = $query->param($param);
Carp::confess "Bad typename '$typename'" unless $typename =~ /(\w+)/;
$typename = $1; # check and untaint
my $type = Foswiki::Configure::Type::load($typename);
my $type = Foswiki::Configure::Type::load($typename, $keys);
my $newval = $type->string2value( $query->param($keys) );
my $xpr = '$this->{values}->' . $keys;
my $curval = eval $xpr;
Expand Down

0 comments on commit 7e60bae

Please sign in to comment.