1package Pod::WSDL::Type;
2
3use strict;
4use warnings;
5use Pod::WSDL::Attr;
6use Pod::WSDL::Utils qw(:writexml :namespaces :types);
7use Pod::WSDL::AUTOLOAD;
8
9our $VERSION = "0.05";
10our @ISA = qw/Pod::WSDL::AUTOLOAD/;
11
12our %FORBIDDEN_METHODS = (
13	name     => {get => 1, set =>  0},
14	wsdlName => {get => 1, set =>  0},
15	array    => {get => 1, set =>  1},
16	descr    => {get => 1, set =>  0},
17	attrs    => {get => 1, set =>  0},
18	writer   => {get => 0, set =>  0},
19);
20
21sub new {
22	my ($pkg, %data) = @_;
23
24	die "A type needs a name, died" unless $data{name};
25
26	my $wsdlName = $data{name};
27	$wsdlName =~ s/(?:^|::)(.)/uc $1/eg;
28
29	my $me = bless {
30		_name     => $data{name},
31		_wsdlName => ucfirst $wsdlName,
32		_array    => $data{array} || 0,
33		_attrs    => [],
34		_descr    => $data{descr} || '',
35		_writer   => $data{writer},
36		_reftype  => 'HASH',
37	}, $pkg;
38
39	$me->_initPod($data{pod}) if $data{pod};
40
41	return $me;
42}
43
44sub _initPod {
45	my $me  = shift;
46	my $pod = shift;
47
48	my @data = split "\n", $pod;
49
50	# Preprocess wsdl pod: trim all lines and concatenate lines not
51	# beginning with wsdl type tokens to previous line.
52	# Ignore first element, if it does not begin with wsdl type token.
53	for (my $i = $#data; $i >= 0; $i--) {
54
55		if ($data[$i] !~ /^\s*(?:_ATTR|_REFTYPE)/i) {
56			if ($i > 0) {
57				$data[$i - 1] .= " $data[$i]";
58				$data[$i] = '';
59			}
60		}
61	}
62
63	for (@data) {
64		s/\s+/ /g;
65		s/^ //;
66		s/ $//;
67
68		if (/^\s*_ATTR\s+/i) {
69			push @{$me->{_attrs}}, new Pod::WSDL::Attr($_);
70		} elsif (/^\s*_REFTYPE\s+(HASH|ARRAY)/i) {
71			$me->reftype(uc $1);
72		}
73	}
74
75}
76
77sub writeComplexType {
78	my $me = shift;
79	my $ownTypes = shift;
80
81	$me->writer->wrElem($START_PREFIX_NAME, "complexType",  name => $me->wsdlName);
82	$me->writer->wrDoc($me->descr, useAnnotation => 1);
83
84	if ($me->reftype eq 'HASH') {
85
86		$me->writer->wrElem($START_PREFIX_NAME, "sequence");
87
88		for my $attr (@{$me->attrs}) {
89			my %tmpArgs = (name => $attr->name,
90				type => Pod::WSDL::Utils::getTypeDescr($attr->type, $attr->array, $ownTypes->{$attr->type}));
91
92			$tmpArgs{nillable} = $attr->nillable if $attr->nillable;
93
94			$me->writer->wrElem($START_PREFIX_NAME, "element", %tmpArgs);
95			$me->writer->wrDoc($attr->descr, useAnnotation => 1);
96			$me->writer->wrElem($END_PREFIX_NAME, "element");
97		}
98
99		$me->writer->wrElem($END_PREFIX_NAME, "sequence");
100	} elsif ($me->reftype eq 'ARRAY') {
101		$me->writer->wrElem($START_PREFIX_NAME, "complexContent");
102		$me->writer->wrElem($START_PREFIX_NAME, "restriction",  base => "soapenc:Array");
103		$me->writer->wrElem($EMPTY_PREFIX_NAME, "attribute",  ref => $TARGET_NS_DECL . ':' . $me->wsdlName, "wsdl:arrayType" => 'xsd:anyType[]');
104		$me->writer->wrElem($END_PREFIX_NAME, "restriction");
105		$me->writer->wrElem($END_PREFIX_NAME, "complexContent");
106	}
107
108	$me->writer->wrElem($END_PREFIX_NAME, "complexType");
109
110	if ($me->array) {
111		$me->writer->wrElem($START_PREFIX_NAME, "complexType",  name => $ARRAY_PREFIX_NAME . ucfirst $me->wsdlName);
112		$me->writer->wrElem($START_PREFIX_NAME, "complexContent");
113		$me->writer->wrElem($START_PREFIX_NAME, "restriction",  base => "soapenc:Array");
114		$me->writer->wrElem($EMPTY_PREFIX_NAME, "attribute",  ref => "soapenc:arrayType", "wsdl:arrayType" => $TARGET_NS_DECL . ':' . $me->wsdlName . '[]');
115		$me->writer->wrElem($END_PREFIX_NAME, "restriction");
116		$me->writer->wrElem($END_PREFIX_NAME, "complexContent");
117		$me->writer->wrElem($END_PREFIX_NAME, "complexType");
118	}
119}
120
1211;
122__END__
123
124=head1 NAME
125
126Pod::WSDL::Type - Represents a type in Pod::WSDL (internal use only)
127
128=head1 SYNOPSIS
129
130  use Pod::WSDL::Type;
131  my $type = new Pod::WSDL::Param(name => 'My::Foo', array => 0, descr => 'My foo bars');
132
133=head1 DESCRIPTION
134
135This module is used internally by Pod::WSDL. It is unlikely that you have to interact directly with it. If that is the case, take a look at the code, it is rather simple.
136
137=head1 METHODS
138
139=head2 new
140
141Instantiates a new Pod::WSDL::Type.
142
143=head3 Parameters
144
145=over 4
146
147=item
148
149name - name of the type, something like 'string', 'boolean', 'My::Foo' etc.
150
151=item
152
153array - if true, an array of the type is used (defaults to 0)
154
155=item
156
157descr - description of the type
158
159=item
160
161pod - the wsdl pod of the type. Please see the section "Pod Syntax" in the description of Pod::WSDL.
162
163=back
164
165=head2 writeComplexType
166
167Write complex type element for XML output. Takes one parameter: ownTypes, reference to hash with own type information
168
169=head1 EXTERNAL DEPENDENCIES
170
171  [none]
172
173=head1 EXAMPLES
174
175see Pod::WSDL
176
177=head1 BUGS
178
179see Pod::WSDL
180
181=head1 TODO
182
183see Pod::WSDL
184
185=head1 SEE ALSO
186
187  Pod::WSDL :-)
188
189=head1 AUTHOR
190
191Tarek Ahmed, E<lt>bloerch -the character every email address contains- oelbsk.orgE<gt>
192
193=head1 COPYRIGHT AND LICENSE
194
195Copyright (C) 2006 by Tarek Ahmed
196
197This library is free software; you can redistribute it and/or modify
198it under the same terms as Perl itself, either Perl version 5.8.5 or,
199at your option, any later version of Perl 5 you may have available.
200
201=cut
202