line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Digital::Driver; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
3
|
|
|
8
|
|
46376
|
$Digital::Driver::AUTHORITY = 'cpan:GETTY'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: Module for new drivers |
6
|
|
|
|
|
|
|
$Digital::Driver::VERSION = '0.002'; |
7
|
3
|
|
|
5
|
|
27
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
107
|
|
8
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
101
|
|
9
|
3
|
|
|
3
|
|
1225
|
use Package::Stash; |
|
3
|
|
|
|
|
14697
|
|
|
3
|
|
|
|
|
90
|
|
10
|
3
|
|
|
3
|
|
18
|
use Carp qw( croak ); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
155
|
|
11
|
3
|
|
|
3
|
|
1608
|
use MooX (); |
|
3
|
|
|
|
|
27695
|
|
|
3
|
|
|
|
|
59
|
|
12
|
3
|
|
|
3
|
|
16
|
use Import::Into; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
51
|
|
13
|
3
|
|
|
3
|
|
783
|
use Digital (); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1043
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub import { |
16
|
3
|
|
|
3
|
|
24
|
my ( $class, @args ) = @_; |
17
|
3
|
|
|
|
|
3
|
my $driver_role; |
18
|
3
|
|
|
|
|
9
|
for (@args) { |
19
|
0
|
0
|
|
|
|
0
|
if ($_ =~ m/^-(.+)/) { |
20
|
0
|
0
|
|
|
|
0
|
croak $class.' already has a driver role' if $driver_role; |
21
|
0
|
|
|
|
|
0
|
$driver_role = 'Digital::Role::'.$1; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
3
|
50
|
|
|
|
10
|
$driver_role = 'Digital::Role' unless $driver_role; |
25
|
3
|
|
|
|
|
8
|
my ( $caller ) = caller; |
26
|
3
|
|
|
|
|
19
|
MooX->import::into($caller); |
27
|
3
|
|
|
|
|
114913
|
$caller->can('with')->($driver_role); |
28
|
3
|
|
|
|
|
16157
|
$class->install_helper($caller); |
29
|
3
|
|
|
|
|
19
|
Digital->register_input($caller); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub install_helper { |
33
|
3
|
|
|
3
|
0
|
6
|
my ( $class, $target ) = @_; |
34
|
3
|
|
|
|
|
50
|
my $stash = Package::Stash->new($target); |
35
|
|
|
|
|
|
|
$stash->add_symbol('&to', sub { |
36
|
6
|
|
|
6
|
|
27
|
my ( $to, $coderef, $via ) = @_; |
37
|
6
|
|
|
|
|
27
|
$target->can('has')->( $to, |
38
|
|
|
|
|
|
|
is => 'lazy', |
39
|
|
|
|
|
|
|
init_arg => undef, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
$stash->add_symbol('&_build_'.$to, sub { |
42
|
5
|
|
|
5
|
|
4136
|
my ( $self ) = @_; |
43
|
5
|
100
|
|
|
|
54
|
my $value = defined $via ? $self->$via : $self->in; |
44
|
5
|
|
|
|
|
38
|
return $coderef->($self,$value) for ($value); |
45
|
6
|
|
|
|
|
1134
|
}); |
46
|
3
|
|
|
|
|
57
|
}); |
47
|
|
|
|
|
|
|
$stash->add_symbol('&overload_to', sub { |
48
|
1
|
|
|
1
|
|
6
|
my ( $to, @args ) = @_; |
49
|
|
|
|
|
|
|
overload->import::into($target, |
50
|
5
|
|
|
5
|
|
2221
|
'0+', sub { shift->$to }, |
51
|
1
|
|
|
|
|
7
|
fallback => 1, |
52
|
|
|
|
|
|
|
); |
53
|
1
|
|
|
|
|
174
|
return $target->can('to')->($to, @args); |
54
|
3
|
|
|
|
|
53
|
}); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |