File Coverage

blib/lib/WWW/Webrobot/Attributes.pm
Criterion Covered Total %
statement 22 22 100.0
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 30 31 96.7


line stmt bran cond sub pod time code
1             package WWW::Webrobot::Attributes;
2 2     2   10 use strict;
  2         3  
  2         66  
3 2     2   11 use warnings;
  2         11  
  2         201  
4              
5             # Author: Stefan Trcek
6             # Copyright(c) 2004 ABAS Software AG
7              
8             sub import {
9 3     3   7 my $self = shift;
10 3         7 my $package = caller(0);
11 3         7 foreach my $attr (@_) {
12 12         21 my $attr_fun = "$package\::$attr";
13 12         16 my $attr_name = "_$attr";
14 12 50       19 if (!defined *{$attr_fun}) {
  12         64  
15             #print "DEFINE $attr_fun as $attr_name\n";
16 2     2   9 no strict;
  2         8  
  2         203  
17 12         2443 *{$attr_fun} = sub {
18 246     246   226 my $self = shift;
19 246         273 my $old = $self->{$attr_name};
20 246 100       449 $self->{$attr_name} = shift if @_;
21 246         705 return $old;
22 12         36 };
23             }
24             }
25             }
26              
27             1;
28              
29             =head1 NAME
30              
31             WWW::Webrobot::Attributes - define setter/getter for attributes of a class
32              
33             =head1 SYNOPSIS
34              
35             use WWW::Webrobot::Attributes qw(attr1 attr2 attr3);
36              
37             =head1 DESCRIPTION
38              
39             This module is used to define setter/getter for attributes.
40             Access:
41              
42             $self->attr1
43             return attribute named 'attr1'
44              
45             $self->attr1($value);
46             set attribute named 'attr1' to value '$value'
47              
48             =cut
49              
50             __END__