| 1 | # ABSTRACT: Create Spec objects from strings | ||||||||||||||
| 2 | |||||||||||||||
| 3 | package Pinto::Target; | ||||||||||||||
| 4 | |||||||||||||||
| 5 | 153 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 153 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 153 | ▶ | use Class::Load; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 153 | ▶ | use Pinto::Exception; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | #------------------------------------------------------------------------------- | ||||||||||||||
| 13 | |||||||||||||||
| 14 | 153 | our $VERSION = '0.14'; # VERSION | |||||||||||||
| 15 | |||||||||||||||
| 16 | #------------------------------------------------------------------------------- | ||||||||||||||
| 17 | |||||||||||||||
| 18 | |||||||||||||||
| 19 | 15 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=5 SCAR=19.7
Pod
documented
| |||||||||||||||
| 20 | 15 | my ( $class, $arg ) = @_; | |||||||||||||
| 21 | |||||||||||||||
| 22 | 15 | my $type = ref $arg; | |||||||||||||
| 23 | 15 | my $target_class; | |||||||||||||
| 24 | |||||||||||||||
| 25 | 15 | ▶ | if ( not $type ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 26 | |||||||||||||||
| 27 | 15 | ▶ | $target_class = | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 28 | ( $arg =~ m{/}x ) | ||||||||||||||
| 29 | ? 'Pinto::Target::Distribution' | ||||||||||||||
| 30 | : 'Pinto::Target::Package'; | ||||||||||||||
| 31 | } | ||||||||||||||
| 32 | elsif ( ref $arg eq 'HASH' ) { | ||||||||||||||
| 33 | |||||||||||||||
| 34 | $target_class = | ||||||||||||||
| 35 | ( exists $arg->{author} ) | ||||||||||||||
| 36 | 0 | ▶ | ? 'Pinto::Target::Distribution' | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | : 'Pinto::Target::Package'; | ||||||||||||||
| 38 | } | ||||||||||||||
| 39 | else { | ||||||||||||||
| 40 | |||||||||||||||
| 41 | # I would just use throw() here, but I need to avoid | ||||||||||||||
| 42 | # creating a circular dependency between this package, | ||||||||||||||
| 43 | # Pinto::Types and Pinto::Util. | ||||||||||||||
| 44 | |||||||||||||||
| 45 | 0 | my $message = "Don't know how to make target from $arg"; | |||||||||||||
| 46 | 0 | Pinto::Exception->throw( message => $message ); | |||||||||||||
| 47 | |||||||||||||||
| 48 | } | ||||||||||||||
| 49 | |||||||||||||||
| 50 | 15 | Class::Load::load_class($target_class); | |||||||||||||
| 51 | 15 | return $target_class->new($arg); | |||||||||||||
| 52 | } | ||||||||||||||
| 53 | |||||||||||||||
| 54 | #------------------------------------------------------------------------------- | ||||||||||||||
| 55 | 153 | 1; | |||||||||||||
| 56 | |||||||||||||||
| 57 | __END__ | ||||||||||||||