| 1 | package Digital::Driver; | ||||||||||
| 2 | 3 | our $AUTHORITY = 'cpan:GETTY'; | |||||||||
| 3 | # ABSTRACT: Module for new drivers | ||||||||||
| 4 | 3 | $Digital::Driver::VERSION = '0.003'; | |||||||||
| 5 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use Package::Stash; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use Carp qw( croak ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | ▶ | use MooX (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 3 | ▶ | use Import::Into; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 3 | ▶ | use Digital (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 3 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=5 SCAR=19.7
| |||||||||||
| 14 | 3 | my ( $class, @args ) = @_; | |||||||||
| 15 | 3 | my $driver_role; | |||||||||
| 16 | 3 | for (@args) { | |||||||||
| 17 | 0 | ▶ | if ($_ =~ m/^-(.+)/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 0 | ▶ | croak $class.' already has a driver role' if $driver_role; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 0 | $driver_role = 'Digital::Role::'.$1; | |||||||||
| 20 | } | ||||||||||
| 21 | } | ||||||||||
| 22 | 3 | ▶ | $driver_role = 'Digital::Role' unless $driver_role; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 3 | my ( $caller ) = caller; | |||||||||
| 24 | 3 | MooX->import::into($caller); | |||||||||
| 25 | 3 | $caller->can('with')->($driver_role); | |||||||||
| 26 | 3 | $class->install_helper($caller); | |||||||||
| 27 | 3 | Digital->register_input($caller); | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 3 | ▶ | sub install_helper { | ||||||||
|
Subroutine
install_helper: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 31 | 3 | my ( $class, $target ) = @_; | |||||||||
| 32 | 3 | my $stash = Package::Stash->new($target); | |||||||||
| 33 | 6 | ▶ | $stash->add_symbol('&to', sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 6 | my ( $to, $coderef, $via ) = @_; | |||||||||
| 35 | 6 | $target->can('has')->( $to, | |||||||||
| 36 | is => 'lazy', | ||||||||||
| 37 | init_arg => undef, | ||||||||||
| 38 | ); | ||||||||||
| 39 | 5 | ▶ | $stash->add_symbol('&_build_'.$to, sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 40 | 5 | my ( $self ) = @_; | |||||||||
| 41 | 5 | ▶ | my $value = defined $via ? $self->$via : $self->in; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 5 | return $coderef->($self,$value) for ($value); | |||||||||
| 43 | 6 | }); | |||||||||
| 44 | 3 | }); | |||||||||
| 45 | 1 | ▶ | $stash->add_symbol('&overload_to', sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 1 | my ( $to, @args ) = @_; | |||||||||
| 47 | overload->import::into($target, | ||||||||||
| 48 | 5 | ▶ | '0+', sub { shift->$to }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 49 | 1 | fallback => 1, | |||||||||
| 50 | ); | ||||||||||
| 51 | 1 | return $target->can('to')->($to, @args); | |||||||||
| 52 | 3 | }); | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 3 | 1; | |||||||||
| 56 | |||||||||||
| 57 | __END__ | ||||||||||