File Coverage

blib/lib/Pinto/Target.pm
Criterion Covered Total %
statement 19 22 86.3
branch 3 8 37.5
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 28 36 77.7


line stmt bran cond sub pod time code
1             # ABSTRACT: Create Spec objects from strings
2              
3             package Pinto::Target;
4              
5 66     66   112640 use strict;
  66         144  
  66         1819  
6 66     66   328 use warnings;
  66         127  
  66         2074  
7              
8 66     66   526 use Class::Load;
  66         6673  
  66         2377  
9              
10 66     66   16222 use Pinto::Exception;
  66         289  
  66         16518  
11              
12             #-------------------------------------------------------------------------------
13              
14             our $VERSION = '0.13'; # VERSION
15              
16             #-------------------------------------------------------------------------------
17              
18              
19             sub new {
20 78     78 1 19830 my ( $class, $arg ) = @_;
21              
22 78         211 my $type = ref $arg;
23 78         174 my $target_class;
24              
25 78 50       284 if ( not $type ) {
    0          
26              
27 78 100       477 $target_class =
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 0       0 ? 'Pinto::Target::Distribution'
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         0 my $message = "Don't know how to make target from $arg";
46 0         0 Pinto::Exception->throw( message => $message );
47              
48             }
49              
50 78         377 Class::Load::load_class($target_class);
51 78         5413 return $target_class->new($arg);
52             }
53              
54             #-------------------------------------------------------------------------------
55             1;
56              
57             __END__
58              
59             =pod
60              
61             =encoding UTF-8
62              
63             =for :stopwords Jeffrey Ryan Thalhammer
64              
65             =head1 NAME
66              
67             Pinto::Target - Create Spec objects from strings
68              
69             =head1 VERSION
70              
71             version 0.13
72              
73             =head1 METHODS
74              
75             =head2 new( $string )
76              
77             [Class Method] Returns either a L<Pinto::Target::Distribution> or
78             L<Pinto::Target::Package> object constructed from the given C<$string>.
79              
80             =head1 AUTHOR
81              
82             Jeffrey Ryan Thalhammer <jeff@stratopan.com>
83              
84             =head1 COPYRIGHT AND LICENSE
85              
86             This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer.
87              
88             This is free software; you can redistribute it and/or modify it under
89             the same terms as the Perl 5 programming language system itself.
90              
91             =cut