File Coverage

blib/lib/Attribute/Method/Tags.pm
Criterion Covered Total %
statement 34 36 94.4
branch 2 4 50.0
condition n/a
subroutine 9 9 100.0
pod 1 1 100.0
total 46 50 92.0


line stmt bran cond sub pod time code
1             package Attribute::Method::Tags;
2              
3 1     1   601 use strict;
  1         1  
  1         38  
4 1     1   7 use warnings;
  1         2  
  1         29  
5              
6 1     1   1035 use Attribute::Handlers;
  1         6651  
  1         5  
7 1     1   807 use Attribute::Method::Tags::Registry;
  1         3  
  1         34  
8 1     1   6 use Carp qw( croak );
  1         1  
  1         68  
9              
10             our $VERSION = '0.11';
11              
12             sub import {
13             # add this package to callers @ISA, as attributes only work via inheritance
14              
15 1     1   5 no strict 'refs';
  1         2  
  1         226  
16              
17 2     2   553 my $caller = caller;
18 2         3 push @{ "${ caller }::ISA" }, __PACKAGE__;
  2         93  
19             }
20              
21             sub Tags : ATTR(CODE,RAWDATA) {
22 4     4 1 26645 my ( $class, $symbol, undef, undef, $data, undef, $file, $line ) = @_;
23              
24 4         33 $data =~ s/^\s+//g;
25              
26 4         14 my @tags = split /\s+/, $data;
27              
28 4 50       13 if ( $symbol eq 'ANON' ) {
29 0         0 die "Cannot tag anonymous subs at file $file, line $line\n";
30             }
31              
32 4         5 my $method = *{ $symbol }{ NAME };
  4         9  
33              
34             { # block for localising $@
35 4         5 local $@;
  4         5  
36              
37 4         16 Attribute::Method::Tags::Registry->add(
38             $class,
39             $method,
40             \@tags,
41             );
42 4 50       20 if ( $@ ) {
43 0         0 croak "Error in adding tags: $@";
44             }
45             }
46 1     1   5 }
  1         2  
  1         8  
47              
48             1;
49              
50             __END__