1package Pod::WSDL::AUTOLOAD; 2 3use Carp; 4use strict; 5use warnings; 6 7our $AUTOLOAD; 8our $VERSION = "0.05"; 9 10sub AUTOLOAD { 11 my $me = shift; 12 my $param = shift; 13 14 my $fbd = ref($me) . '::FORBIDDEN_METHODS'; 15 16 my $attr = $AUTOLOAD; 17 $attr =~ s/.*:://; 18 19 if (@_) { 20 croak ref $me . " received call to '$attr' with too many params (max 1). Call was '$attr($param, " . join (", ", @_) . ")'!"; 21 } 22 23 if ($attr eq "DESTROY"){ 24 return; 25 } elsif (exists $me->{'_' . $attr}) { 26 no strict 'refs'; 27 if (defined $param) { 28 croak ref ($me) . " does not allow setting of '$attr', died" if (caller)[0] ne ref($me) and %$fbd and $fbd->{$attr} and !$fbd->{$attr}->{set}; 29 $me->{'_' . $attr} = $param; 30 return $me; 31 } else { 32 croak ref ($me) . " does not allow getting of '$attr', died" if (caller)[0] ne ref($me) and %$fbd and $fbd->{$attr} and !$fbd->{$attr}->{get}; 33 #if (ref $me->{'_' . $attr} eq 'ARRAY') { 34 # return @{$me->{'_' . $attr}}; 35 #} elsif (ref $me->{'_' . $attr} eq 'HASH') { 36 # return %{$me->{'_' . $attr}}; 37 #} elsif (ref $me->{'_' . $attr} eq 'SCALAR') { 38 # return ${$me->{'_' . $attr}}; 39 #} else { 40 return $me->{'_' . $attr}; 41 #} 42 } 43 } else { 44 croak "I have no method called '$attr()'!"; 45 } 46} 47 481; 49__END__ 50 51=head1 NAME 52 53Pod::WSDL::AUTOLOAD - Base class for autoloading (internal use only) 54 55=head1 SYNOPSIS 56 57 package Foo; 58 our @ISA = qw/Pod::WSDL::AUTOLOAD/; 59 60 sub new { 61 my $pgk = shift; 62 bless { 63 _bar => 'blah', 64 }, $pgk 65 } 66 67 package main; 68 use Foo; 69 70 my $foo = new Foo(); 71 print $foo->bar; # prints 'blah' 72 73 $foo->bar('bloerch'); # sets _bar to 'bloerch' 74 75 76=head1 DESCRIPTION 77 78This module is used internally by Pod::WSDL. It is unlikely that you have to interact directly with it. The Pod::WSDL::AUTOLOADER is used as a base class and handels autoloading of accessor methods. If there is a property called _foo in a hash based blessed reference, it will allow the use of the method 'foo' as a getter and setter. As a getter is returns the value of _foo, as a setter it sets _foo with the argument and returns the object. You can exclude the accessor by using a hash %FORBIDDEN_METHODS in the derived class like that: 79 80 our %FORBIDDEN_METHODS = ( 81 foo => {get => 1, set => 0}, 82 bar => {get => 0, set => 0} 83 ); 84 85In this example it will not be allowed to set _foo and to set or get _bar. If the user of the object tries to do so, it croaks. From within the objects package every accessor is allowed. 86 87=head1 METHODS 88 89[none] 90 91=head1 EXTERNAL DEPENDENCIES 92 93 Carp; 94 95=head1 EXAMPLES 96 97see Pod::WSDL 98 99=head1 BUGS 100 101see Pod::WSDL 102 103=head1 TODO 104 105see Pod::WSDL 106 107=head1 SEE ALSO 108 109 Pod::WSDL :-) 110 111=head1 AUTHOR 112 113Tarek Ahmed, E<lt>bloerch -the character every email address contains- oelbsk.orgE<gt> 114 115=head1 COPYRIGHT AND LICENSE 116 117Copyright (C) 2006 by Tarek Ahmed 118 119This library is free software; you can redistribute it and/or modify 120it under the same terms as Perl itself, either Perl version 5.8.5 or, 121at your option, any later version of Perl 5 you may have available. 122 123=cut 124