File: AUTOLOAD.pm

package info (click to toggle)
libpod-wsdl-perl 0.063-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 316 kB
  • sloc: perl: 1,808; xml: 44; makefile: 2
file content (123 lines) | stat: -rw-r--r-- 3,126 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package Pod::WSDL::AUTOLOAD;

use Carp;
use strict;
use warnings;

our $AUTOLOAD;
our $VERSION = "0.05";

sub AUTOLOAD {
    my $me     = shift;
    my $param  = shift;
    
    my $fbd = ref($me) . '::FORBIDDEN_METHODS';
    
    my $attr   = $AUTOLOAD;
    $attr =~ s/.*:://;

    if (@_) {
		croak ref $me . " received call to '$attr' with too many params (max 1). Call was '$attr($param, " . join (", ",  @_) .  ")'!"; 
    }
    
    if ($attr eq "DESTROY"){
		return;
    } elsif (exists $me->{'_' . $attr}) {
    	no strict 'refs';
		if (defined $param) {
			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};
		    $me->{'_' . $attr} = $param; 
	    	return $me;
		} else {
			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};
		    #if (ref $me->{'_' . $attr} eq 'ARRAY') {
			#    return @{$me->{'_' . $attr}};
		    #} elsif (ref $me->{'_' . $attr} eq 'HASH') {
			#    return %{$me->{'_' . $attr}};
		    #} elsif (ref $me->{'_' . $attr} eq 'SCALAR') {
			#    return ${$me->{'_' . $attr}};
		    #} else {
		    	return $me->{'_' . $attr};
		    #}
		}
    } else {
		croak "I have no method called '$attr()'!";
    }
}

1;
__END__

=head1 NAME

Pod::WSDL::AUTOLOAD - Base class for autoloading (internal use only)

=head1 SYNOPSIS

  package Foo;
  our @ISA = qw/Pod::WSDL::AUTOLOAD/;

  sub new {
    my $pgk = shift;
    bless {
  	  _bar => 'blah',
    }, $pgk
  }

  package main;
  use Foo;
  
  my $foo = new Foo();
  print $foo->bar;  # prints 'blah'
  
  $foo->bar('bloerch');  # sets _bar to 'bloerch'
  
  
=head1 DESCRIPTION

This 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:

  our %FORBIDDEN_METHODS = (
	foo => {get => 1, set => 0},
	bar => {get => 0, set => 0}
  );

In 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.

=head1 METHODS

[none]

=head1 EXTERNAL DEPENDENCIES

  Carp;

=head1 EXAMPLES

see Pod::WSDL

=head1 BUGS

see Pod::WSDL

=head1 TODO

see Pod::WSDL

=head1 SEE ALSO

  Pod::WSDL :-)
 
=head1 AUTHOR

Tarek Ahmed, E<lt>bloerch -the character every email address contains- oelbsk.orgE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2006 by Tarek Ahmed

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.5 or,
at your option, any later version of Perl 5 you may have available.

=cut