File Coverage

blib/lib/Rope/Conditional.pm
Criterion Covered Total %
statement 22 29 75.8
branch 2 6 33.3
condition 1 2 50.0
subroutine 8 8 100.0
pod n/a
total 33 45 73.3


line stmt bran cond sub pod time code
1             package Rope::Conditional;
2              
3 1     1   1168 use strict; use warnings;
  1     1   2  
  1         39  
  1         5  
  1         3  
  1         55  
4              
5             my (%PRO);
6              
7 1     1   5 use Rope::Pro;
  1         2  
  1         20  
8 1     1   770 use Struct::Conditional;
  1         3670  
  1         58  
9              
10             BEGIN {
11 1     1   7 %PRO = Rope::Pro->new;
12             }
13              
14             sub import {
15 1     1   13 my ($caller, $pkg) = (scalar caller);
16             $PRO{keyword}($caller, 'conditional', sub {
17 1     1   48 my ($name, %conditional) = @_;
18 1         10 my ($meta, $class, $data) = (Rope->get_meta($caller), 'Struct::Conditional');
19              
20 1 50       7 if ($meta->{properties}->{$name}) {
21 0 0       0 if ($meta->{properties}->{$name}->{conditional}) {
22 0         0 Rope->clear_property($caller, $name);
23             } else {
24 0         0 die 'Cannot extend Object($caller) with a conditional property ($prop) as a property with that name is already defined';
25             }
26             }
27 1 50       5 if (ref $_[1]) {
28 0         0 $pkg = $class = $_[1]->[0] . '::Conditional';
29 0         0 $pkg =~ s/\:\:/\//g;
30 0         0 require $pkg . '.pm';
31 0         0 $data = $_[1]->[1];
32             }
33            
34             $caller->property($name,
35 1   50 1   3 value => sub { shift; $class->new()->compile($data || \%conditional, @_, 1) },
  1         18  
36 1         15 conditional => 1
37             );
38 1         9 });
39             }
40              
41             1;
42              
43             __END__