File: Target.pm

package info (click to toggle)
pinto 0.14000-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,900 kB
  • sloc: perl: 12,566; sh: 255; makefile: 7
file content (91 lines) | stat: -rw-r--r-- 1,898 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# ABSTRACT: Create Spec objects from strings

package Pinto::Target;

use strict;
use warnings;

use Class::Load;

use Pinto::Exception;

#-------------------------------------------------------------------------------

our $VERSION = '0.14'; # VERSION

#-------------------------------------------------------------------------------


sub new {
    my ( $class, $arg ) = @_;

    my $type = ref $arg;
    my $target_class;

    if ( not $type ) {

        $target_class =
            ( $arg =~ m{/}x )
            ? 'Pinto::Target::Distribution'
            : 'Pinto::Target::Package';
    }
    elsif ( ref $arg eq 'HASH' ) {

        $target_class =
            ( exists $arg->{author} )
            ? 'Pinto::Target::Distribution'
            : 'Pinto::Target::Package';
    }
    else {

        # I would just use throw() here, but I need to avoid
        # creating a circular dependency between this package,
        # Pinto::Types and Pinto::Util.

        my $message = "Don't know how to make target from $arg";
        Pinto::Exception->throw( message => $message );

    }

    Class::Load::load_class($target_class);
    return $target_class->new($arg);
}

#-------------------------------------------------------------------------------
1;

__END__

=pod

=encoding UTF-8

=for :stopwords Jeffrey Ryan Thalhammer

=head1 NAME

Pinto::Target - Create Spec objects from strings

=head1 VERSION

version 0.14

=head1 METHODS

=head2 new( $string )

[Class Method] Returns either a L<Pinto::Target::Distribution> or
L<Pinto::Target::Package> object constructed from the given C<$string>.

=head1 AUTHOR

Jeffrey Ryan Thalhammer <jeff@stratopan.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut