[%
#
# extension
#
# unfortunately, SOAP::WSDL's speed tweaks don't play well with
# Class::Std's inheritance model.
#
# In Class::Std, all properties are stored in the class, and in objects
# using inheritance in the defining class.
#
# As the speed tweaks directly access the class' data without checking
# inheritance, the simplest way is to resolve complexType extension
# relationships
#
# To capture deep inheritance, extensions must be followed until a non-
# extension base is found
#
# TODO attribute handling is missing
# TODO sort out some better way to handle inheritance

element_list = [];

# copy complexType ref
base_type = complexType;
base_name = base_type.expand( base_type.get_base );
base_type = definitions.first_types.find_type( base_name );

# add a use base for first to setup inheritance
%]
use base qw([% XSD.create_xsd_name( base_type ) %]);
[%
# loop forever
WHILE (1);
    IF (complexType.get_variety == 'extension');
        # wrap statement in IF to avoid printing
        IF (complexType.set_variety( base_type.get_variety )); END;
    END;
    # make a copy. We don't want to modify the original list here...
    FOREACH element = base_type.get_element.reverse;
        element_list.unshift(element);
    END;
    # get next base type if there is one...
    IF (base_type.get_base);
        base_name=base_type.expand( base_type.get_base );
        # set new base_type
        base_type = definitions.first_types.find_type( base_name );
    ELSE;
        # exit loop if there is none
        BREAK;
    END;
END;

#
# and now the new elements...
#
element_from = complexType.get_element;

FOREACH element = element_from;
    IF element_list.${ loop.index }.get_name != element.get_name;
        element_list.push( element );
    END;
END;

# set derived element list
# wrap in IF; END; to prevent it getting printed
IF ( complexType.set_element( element_list ) ); END;

-%]
# Variety: [% complexType.get_variety %]
[%
INCLUDE complexType/variety.tt(complexType = complexType);

# restore original element list
# wrap in IF; END; to prevent it getting printed
IF ( complexType.set_element( element_from ) ); END;

%]