[% IF (complexType.get_attribute.size) -%]
package [% XSD.create_xmlattr_name(complexType) %];
use base qw(SOAP::WSDL::XSD::Typelib::AttributeSet);

{ # BLOCK to scope variables
[% FOREACH element = complexType.get_attribute;
    WHILE element.get_ref;
        element = definitions.first_types.find_attribute(element.expand( element.get_ref ));
    END; %]
my %[% element.get_name %]_of :ATTR(:get<[% element.get_name %]>);
[%- END %]

__PACKAGE__->_factory(
    [ qw(
[%- FOREACH element = complexType.get_attribute;
        WHILE element.get_ref;
            element = definitions.first_types.find_attribute(element.expand( element.get_ref ));
        END; %]
        [% element.get_name -%]
[% END %]
    ) ],
    {
[% FOREACH element = complexType.get_attribute;
        WHILE element.get_ref;
            element = definitions.first_types.find_attribute(element.expand( element.get_ref ));
        END; %]
        [% element.get_name %] => \%[% element.get_name %]_of,
[% END -%]
    },
    {
[% FOREACH element = complexType.get_attribute;
    IF (type = element.get_type);
        element_type = definitions.first_types.find_type(complexType.expand( type ));
-%]
        [% element.get_name %] => '[% XSD.create_xsd_name(element_type) %]',
[%
    ELSIF (ref = element.get_ref);
            WHILE element.get_ref;
                element = definitions.first_types.find_attribute(element.expand( element.get_ref ));
            END;
%]
            [% element.get_name %] => '[% XSD.create_xsd_name(element) %]',
[%  ELSIF (element.first_simpleType);
            THROW NOT_IMPLEMENTED , "Attributes with atomic simpleType definition are not implemented yet";
            atomic_types.${ element.get_name } = element.first_simpleType;
    ELSE;
            THROW NOT_IMPLEMENTED , "Neither simple nor complex atomic type for attribute ${ element.get_name } in ${ complexType.get_name } - don't know what to do with it";
    END;
END -%]
    }
);

} # end BLOCK
[% END %]