File Coverage

blib/lib/Rope/Type.pm
Criterion Covered Total %
statement 30 31 96.7
branch 7 8 87.5
condition n/a
subroutine 8 8 100.0
pod n/a
total 45 47 95.7


line stmt bran cond sub pod time code
1             package Rope::Type;
2              
3 1     1   489 use strict; use warnings;
  1     1   1  
  1         26  
  1         3  
  1         1  
  1         33  
4 1     1   560 use Types::Standard;
  1         105339  
  1         7  
5 1     1   1990 use Rope::Pro;
  1         2  
  1         57  
6             my (%PRO);
7              
8             BEGIN {
9 1     1   9 %PRO = Rope::Pro->new(
10             type_map => {
11             int => 'Int',
12             bool => 'Bool',
13             str => 'Str',
14             hash => 'HashRef',
15             array => 'ArrayRef',
16             scalar => 'ScalarRef',
17             code => 'CodeRef',
18             file => 'FileHandle',
19             obj => 'Object'
20             }
21             );
22             }
23              
24             sub import {
25 1     1   11 my ($caller, $pkg, @types) = (scalar caller, @_);
26              
27 1 50       4 @types = keys %{$PRO{type_map}} unless scalar @types;
  0         0  
28              
29 1         2 for (@types) {
30 1     1   5 no strict 'refs';
  1         1  
  1         203  
31 9         5 my $type = &{"Types::Standard::$PRO{type_map}{$_}"};
  9         29  
32             $PRO{keyword}($caller, $_, sub {
33 8     8   160872 my (@params) = @_;
34 8         13 my $count = scalar @params;
35 8 100       32 return $type unless $count;
36 6 100       16 if ($count <= 2) {
37 5 100       28 $caller->property($params[0],
38             type => $type,
39             initable => 1,
40             enumerable => 1,
41             writeable => 1,
42             (defined $params[1] ? (value => $params[1]) : ()),
43             );
44             } else {
45 1         3 my $name = shift @params;
46 1         4 $caller->property($name, @params, type => $type);
47             }
48 6         15 return;
49 9         51 });
50             }
51             }
52              
53             1;
54              
55             __END__