File Coverage

blib/lib/Rope/Chain.pm
Criterion Covered Total %
statement 23 25 92.0
branch 5 6 83.3
condition 2 2 100.0
subroutine 6 7 85.7
pod n/a
total 36 40 90.0


line stmt bran cond sub pod time code
1             package Rope::Chain;
2              
3 5     5   2864 use strict; use warnings;
  5     5   14  
  5         224  
  5         27  
  5         9  
  5         318  
4             my (%PRO);
5              
6 5     5   29 use Rope::Pro;
  5         11  
  5         312  
7              
8             BEGIN {
9 5     5   28 %PRO = Rope::Pro->new();
10             }
11              
12             sub import {
13 5     5   62 my ($caller) = (scalar caller);
14             $PRO{keyword}($caller, 'chain', sub {
15 14     14   183 my ($name, @factory) = @_;
16              
17 14         89 my ($meta, $chain, $exists) = (Rope->get_meta($caller), [], 0);
18 14 100       69 if ($meta->{properties}->{$name}) {
19 11   100     51 $chain = $meta->{properties}->{$name}->{after} || [];
20 11         27 $exists = 1;
21             }
22 14         76 my ($prop, $cb) = (shift(@factory), shift(@factory));
23 14 50       47 if ($meta->{properties}->{$prop}) {
24 0         0 die 'Cannot extend Object($caller) with a chain property ($prop) as a property with that name is already defined';
25             }
26             $caller->property($prop,
27 0     0   0 value => sub { $cb->(@_); }
28 14         111 );
29 14 100       38 if (!$exists) {
30 3         33 $caller->property($name,
31             value => $cb,
32             );
33             } else {
34 11         38 $caller->after($name, $cb);
35             }
36 5         44 });
37             }
38              
39             1;
40              
41             __END__