File Coverage

blib/lib/Digital.pm
Criterion Covered Total %
statement 31 34 91.1
branch 1 4 25.0
condition n/a
subroutine 9 9 100.0
pod 0 2 0.0
total 41 49 83.6


line stmt bran cond sub pod time code
1             package Digital;
2             BEGIN {
3 3     5   721 $Digital::AUTHORITY = 'cpan:GETTY';
4             }
5             # ABSTRACT: Handling conversion of digital values towards physical units
6             $Digital::VERSION = '0.002';
7 3     3   18 use strict;
  3         5  
  3         86  
8 3     3   13 use warnings;
  3         4  
  3         98  
9 3     3   480 use Package::Stash;
  3         8947  
  3         108  
10 3     3   19 use Module::Runtime qw( use_module );
  3         4  
  3         18  
11              
12             our %inputs;
13              
14             sub register_input {
15 3     3 0 8 my ( undef, $input, $input_class ) = @_;
16 3 50       10 unless (defined $input_class) {
17 3         4 $input_class = $input;
18 3         9 $input = lc($input_class);
19 3         9 $input =~ s!::!_!g;
20 3         6 $input =~ s!^digitalx_!!g;
21             }
22 3         224 $inputs{$input} = $input_class;
23             }
24              
25             sub input {
26 2     2 0 6 my ( $class, $input, @args ) = @_;
27 2         5 my $input_class = $inputs{$input};
28 2         18 return $input_class->input(@args);
29             }
30              
31             sub import {
32 3     3   101 my ( $class, @args ) = @_;
33 3         9 my ( $caller ) = caller;
34 3         36 my $stash = Package::Stash->new($caller);
35 3         6 my @classes;
36 3 0       11 for (@args) { unless (/^-/) {
  0         0  
37 0         0 push @classes, 'DigitalX::'.$_;
38             } }
39 3         7 for (@classes) {
40 0         0 use_module($_);
41             }
42 3     2   2495 $stash->add_symbol('&input', sub { return $class->input(@_) });
  2         23  
43             }
44              
45             1;
46              
47             __END__