File: Base.pm

package info (click to toggle)
libsoap-wsdl-perl 3.004-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,600 kB
  • sloc: perl: 8,433; xml: 1,769; java: 19; makefile: 15
file content (28 lines) | stat: -rw-r--r-- 888 bytes parent folder | download | duplicates (6)
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
package Typelib::Base;
use Class::Std::Fast::Storable;

sub mk_add_mutators {
    my $class = shift;
    my $attributes = shift;
    for my $method ( keys %{$ attributes }) {
       *{ "$class\::add_$method" } = sub {
           my ($self, $value) = @_;
           my $ident = ${ $self };
           
           # we're the first value
           return $attributes->{ $method }->{ $ident } = $value
                if not defined $attributes->{ $method }->{ $ident };

           # we're the second value
           return $attributes->{ $method }->{ $ident } = [
                $attributes->{ $method }->{ $ident }, $value ]
                    if not ref $attributes->{ $method }->{ $ident } eq 'ARRAY';

           # we're third or later
           push @{ $attributes->{ $method }->{ $ident } }, $value;
           return $attributes->{ $method }->{ $ident }; 
       } 
    }
}

1;