IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5961


Ignore:
Timestamp:
Jan 10, 2006, 12:49:37 PM (21 years ago)
Author:
jhoblitt
Message:

enable support for complex config files
add complex_config()
add tabledata_from_meta()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/glueforge/glueforge.in

    r5955 r5961  
    33# Copyright (C) 2005  Joshua Hoblitt
    44#
    5 # $Id: glueforge.in,v 1.39 2006-01-10 00:38:15 jhoblitt Exp $
     5# $Id: glueforge.in,v 1.40 2006-01-10 22:49:37 jhoblitt Exp $
    66
    77use strict;
     
    4242my $data; # hashref
    4343if ($complex) {
    44 #    $data = complex_config($config);
     44    $data = complex_config($config);
    4545} else {
    4646    $data = simple_config($config);
     
    205205}
    206206
     207sub complex_config {
     208    my $config = shift;
     209
     210    # find the glueforge metadata
     211    my $glueforge_meta;
     212    for (my $i = 0; $i < @{$config}; $i++) {
     213        my $elem = $config->[$i];
     214
     215        if ($elem->{name} eq "glueforge") {
     216            $glueforge_meta = $elem;
     217
     218            # delete element from array
     219            splice @$config, $i, 1;
     220
     221            last;
     222        }
     223    }
     224
     225    die "missing glueforge METADATA" unless defined $glueforge_meta;
     226
     227    my %data;
     228
     229    # global data
     230    my $pkg_name = $glueforge_meta->{value}->[0]->{value};
     231    $data{pkg_name}         = $pkg_name . "db";
     232    $data{pkg_namespace}    = $pkg_name;
     233
     234    # setup one table per nested metadata
     235    my @tables;
     236    foreach my $meta (@{$config}) {
     237        push @tables, tabledata_from_meta($meta);
     238    }
     239
     240    $data{tables} = \@tables;
     241
     242    return \%data;
     243}
     244
     245sub tabledata_from_meta {
     246    my $meta = shift;   # hashref
     247
     248    die "not a valid metadata" unless $meta->{class} eq 'metadata';
     249
     250    my $table_name = $meta->{name};
     251
     252    my @fields;
     253    foreach my $column (@{$meta->{value}}) {
     254        my $mdtypes = lookup_type( $column->{type} );
     255        next if not defined $mdtypes;
     256
     257        push @fields, {
     258            name    => $column->{name},
     259            type    => $column->{type},
     260            ctype   => $mdtypes->{ctype},
     261            mtype   => $mdtypes->{mtype},
     262            test    => $mdtypes->{test},
     263            comment => $column->{comment},
     264            value   => $column->{value},
     265        };
     266    }
     267
     268    my %table = (
     269        name        => $table_name,
     270        namespace   => $table_name,
     271        object_name => $table_name . "Row",
     272        columns     => \@fields,
     273    );
     274
     275    return \%table;
     276}
     277
    207278__END__
    208279
Note: See TracChangeset for help on using the changeset viewer.