File Coverage

blib/lib/Class/Accessor/Installer.pm
Criterion Covered Total %
statement 29 43 67.4
branch 4 16 25.0
condition 1 6 16.6
subroutine 7 8 87.5
pod 2 2 100.0
total 43 75 57.3


line stmt bran cond sub pod time code
1 1     1   24854 use 5.006;
  1         3  
  1         52  
2 1     1   5 use warnings;
  1         2  
  1         31  
3 1     1   5 use strict;
  1         2  
  1         80  
4              
5             package Class::Accessor::Installer;
6             our $VERSION = '1.100880';
7              
8             # ABSTRACT: Install an accessor subroutine
9 1     1   926 use Sub::Name;
  1         781  
  1         59  
10 1     1   996 use UNIVERSAL::require;
  1         1576  
  1         10  
11              
12             sub install_accessor {
13 4     4 1 99 my ($self, %args) = @_;
14 4         11 my ($package, $name, $code) = @args{qw(package name code)};
15 4 50       11 unless (defined $package) {
16 4   33     19 $package = ref $self || $self;
17             }
18 4 50       15 $name = [$name] unless ref $name eq 'ARRAY';
19 4         6 my @caller;
20 4 50       11 if ($::PTAGS) {
21 0         0 my $level = 1;
22 0         0 do { @caller = caller($level++) }
  0         0  
23             while $caller[0] =~ /^Class(::\w+)*::Accessor::/o;
24             }
25 4         8 for my $sub (@$name) {
26 1     1   138 no strict 'refs';
  1         1  
  1         286  
27 4 50       12 $::PTAGS && $::PTAGS->add_tag($sub, $caller[1], $caller[2]);
28 4         29 *{"${package}::${sub}"} = subname "${package}::${sub}" => $code;
  4         34  
29             }
30             }
31              
32             sub document_accessor {
33 0     0 1   my ($self, %args) = @_;
34              
35             # Don't use() it - this should still work if we don't have
36             # Sub::Documentation.
37 0           Sub::Documentation->require;
38 0 0         return if $@;
39 0           my $package = delete $args{package};
40 0 0         unless (defined $package) {
41 0   0       $package = ref $self || $self;
42             }
43 0           my $name = delete $args{name};
44 0 0         $name = [$name] unless ref $name eq 'ARRAY';
45 0           my $belongs_to = delete $args{belongs_to};
46 0           while (my ($type, $documentation) = each %args) {
47 0 0         Sub::Documentation::add_documentation(
48             package => $package,
49             name => $name,
50             glob_type => 'CODE',
51             type => $type,
52             documentation => $documentation,
53             ($belongs_to ? (belongs_to => $belongs_to) : ()),
54             );
55             }
56             }
57             1;
58              
59              
60             __END__