1package SOAP::WSDL::Generator::PrefixResolver;
2use strict; use warnings;
3
4use Class::Std::Fast::Storable;
5
6our $VERSION = 3.004;
7
8my %namespace_prefix_map_of :ATTR(:name<namespace_prefix_map>   :default<{}>);
9my %namespace_map_of        :ATTR(:name<namespace_map>          :default<{}>);
10my %prefix_of               :ATTR(:name<prefix> :default<{}>);
11
12sub resolve_prefix {
13    my ($self, $type, $namespace, $element) = @_;
14    my $prefix;
15    if (not defined($namespace)) {
16        $prefix = $prefix_of{ $$self }->{ $type }
17    }
18    else {
19        $prefix = $namespace_prefix_map_of{ $$self }->{ $namespace }
20            || ( ($namespace_map_of{ $$self }->{ $namespace })
21                ? join ('::', $prefix_of{ $$self }->{ $type }, $namespace_map_of{ $$self }->{ $namespace })
22                : $prefix_of{ $$self }->{ $type }
23            );
24    }
25    return "${prefix}::";
26}
27
281;
29
30__END__
31
32=pod
33
34=head1 NAME
35
36SOAP::WSDL::Generator::PrefixResolver - prefixes for different classes
37
38=head1 SYNOPSIS
39
40If you want to create your custom prefix resolver:
41
42 package MyPrefixResolver;
43 use strict; use warnings;
44 use base qw(SOAP::WSDL::Generator::PrefixResolver);
45
46 sub resolve_prefix {
47     my ($self, $type, $namespace, $node) = @_;
48     # return something special
49     return $self->SUPER::resolve_prefix($type, $namespace, $node);
50 }
51
52When generating code:
53
54 use MyPrefixResolver;
55 use SOAP::WSDL::Generator::XSD;
56 my $generator = SOAP::WSDL::Generator::Template::XSD->new({
57    prefix_resolver_class => 'MyPrefixResolver',
58 });
59
60=head1 DESCRIPTION
61
62Prefix resolver class for SOAP::WSDL's code generator. You may subclass it to
63apply some custom prefix resolving logic.
64
65Subclasses must implement the following methods:
66
67=over
68
69=item * resolve_prefix
70
71 sub resolve_prefix {
72    my ($self, $namespace, $node) = @_;
73    # ...
74 }
75
76resolve_prefix is expected to return a (perl class) prefix. It is called with
77the following parameters:
78
79 NAME       DESCRIPTION
80 -----------------------------------------------------------------------------
81 type       One of (server|interface|typemap|type|element|attribute)
82 namespace  The targetNamespace of the node to generate a prefix for.
83 node       The node to generate a prefix for
84
85You usually just need type and namespace for prefix resolving. node is
86provided for rather funky setups, where you have to choose different prefixes
87based on type names or whatever.
88
89Node may be of any of the following classes:
90
91 SOAP::WSDL::Service
92 SOAP::WSDL::XSD::Attribute
93 SOAP::WSDL::XSD::Element
94 SOAP::WSDL::XSD::Type
95
96Note that both namespace and node may be undef - you should test for
97definedness before doing anything fancy with them.
98
99If you want your prefixes to represent perl class hierarchies, they should
100end with '::'.
101
102Example:
103
104Imagine you're generating interfaces for the Acme Pet Shop. Acme Corp. has
105set up their datatypes to be global across all interfaces (and products), while
106elements are local to the product (the Pet Shop in the example).
107All elements are in the urn:Acme namespace.
108
109In addition, there are types in the namespace urn:Acme:Goods, which should go
110into the same namespace as types, but be prefixed with 'Goods_'
111
112You may want prefixes (roughly) like this:
113
114 Interfaces:        Acme::Client::PetShop::
115 Server:            Acme::Server::PetShop::
116 Types:             Acme::Types::
117 Types (Goods):     Acme::Types::Goods_
118 Elements:          Acme::Elements::PetShop::
119 Typemaps:          Acme::Typemaps::PetShop::
120
121=back
122
123=head1 BUGS AND LIMITATIONS
124
125You cannot suffix your types by some rule yet...
126
127=head1 LICENSE AND COPYRIGHT
128
129Copyright 2008 Martin Kutter.
130
131This file is part of SOAP-WSDL. You may distribute/modify it under
132the same terms as perl itself
133
134=head1 AUTHOR
135
136Martin Kutter E<lt>martin.kutter fen-net.deE<gt>
137
138=head1 REPOSITORY INFORMATION
139
140 $Rev: 583 $
141 $LastChangedBy: kutterma $
142 $Id: $
143 $HeadURL: $
144
145=cut
146