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