| 1 | =head1 NAME | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | Pipeline::Config - configuration files for building Pipelines. | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | use Error qw( :try ); | ||||||||||||||||||||
| 8 | use Pipeline::Config; | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | my $config = Pipeline::Config->new(); | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | try { | ||||||||||||||||||||
| 13 | my $pipe = $config->load( 'somefile.type' ); | ||||||||||||||||||||
| 14 | my $pipe2 = $config->load( 'somefile', 'type' ); | ||||||||||||||||||||
| 15 | } catch Error with { | ||||||||||||||||||||
| 16 | print shift; | ||||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | =cut | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | package Pipeline::Config; | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | 1 | ▶ | use warnings::register; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 1 | ▶ | use Error; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | 1 | ▶ | use Pipeline::Config::LoadError; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | 1 | ▶ | use Pipeline::Config::UnknownTypeError; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 1 | ▶ | use base qw( Pipeline::Base ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 1 | our $VERSION = '0.05'; | |||||||||||||||||||
| 33 | 1 | our $REVISION = (split(/ /, ' $Revision: 1.13 $ '))[2]; | |||||||||||||||||||
| 34 | 1 | our $TYPES = { # maybe should use regexps here? | |||||||||||||||||||
| 35 | 'yml' => 'Pipeline::Config::YAML', | ||||||||||||||||||||
| 36 | 'yaml' => 'Pipeline::Config::YAML', | ||||||||||||||||||||
| 37 | }; | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 8 | ▶ | sub types { | ||||||||||||||||||
|
Subroutine
types: called CC=2 SCAR=8.4
Pod
documented
| |||||||||||||||||||||
| 40 | 8 | my $self = shift; | |||||||||||||||||||
| 41 | 0 | ▶ | if (@_) { $TYPES = shift; return $self; } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 8 | else { return $TYPES; } | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 4 | ▶ | sub load { | ||||||||||||||||||
|
Subroutine
load: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 46 | 4 | my $self = shift; | |||||||||||||||||||
| 47 | 4 | my $file = shift; | |||||||||||||||||||
| 48 | 4 | my $type = shift; | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 4 | ▶ | $type = $self->resolve_type( $file ) unless ($type); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 4 | return $self->load_type( $file, $type ); | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 4 | ▶ | sub load_type { | ||||||||||||||||||
|
Subroutine
load_type: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||||||||||||
| 56 | 4 | my $self = shift; | |||||||||||||||||||
| 57 | 4 | my $file = shift; | |||||||||||||||||||
| 58 | 4 | my $type = shift; | |||||||||||||||||||
| 59 | 4 | my $parser = $self->new_object( $type ); | |||||||||||||||||||
| 60 | 0 | return $parser->load( $file ); | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 4 | ▶ | sub resolve_type { | ||||||||||||||||||
|
Subroutine
resolve_type: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 64 | 4 | my $self = shift; | |||||||||||||||||||
| 65 | 4 | my $file = shift; | |||||||||||||||||||
| 66 | 4 | foreach my $type (keys %{ $self->types }) { | |||||||||||||||||||
| 67 | 7 | ▶ | return $type if ($file =~ /\.$type/i) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | 0 | throw Pipeline::Config::UnknownTypeError( "can't resolve type of [$file]!" ); | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 4 | ▶ | sub new_object { | ||||||||||||||||||
|
Subroutine
new_object: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||
| 73 | 4 | my $self = shift; | |||||||||||||||||||
| 74 | 4 | my $type = shift; | |||||||||||||||||||
| 75 | 4 | ▶ | my $class = $self->get_types_class( $type ) | ||||||||||||||||||
|
Condition33%1/3
$self->get_types_class($type) || 'Pipeline::Config::UnknownTypeError'->throw("unknown type: $type")
MC/DC0%0/2
$self->get_types_class($type) || 'Pipeline::Config::UnknownTypeError'->throw("unknown type: $type")
$self->get_types_class($type)
'Pipeline::Config::UnknownTypeError'->throw("unknown type: $type")
Truth table33%1/3
A || B
A= $self->get_types_class($type)B= 'Pipeline::Config::UnknownTypeError'->throw("unknown type: $type")
| |||||||||||||||||||||
| 76 | || throw Pipeline::Config::UnknownTypeError( "unknown type: $type" ); | ||||||||||||||||||||
| 77 | 4 | return $self->load_class( $class )->new( @_ )->debug( $self->debug ); | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 4 | ▶ | sub get_types_class { | ||||||||||||||||||
|
Subroutine
get_types_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 81 | 4 | my $self = shift; | |||||||||||||||||||
| 82 | 4 | my $type = shift; | |||||||||||||||||||
| 83 | 4 | return Pipeline::Config->types->{$type}; | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 4 | ▶ | sub load_class { | ||||||||||||||||||
|
Subroutine
load_class: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||||||||
| 87 | 4 | my $self = shift; | |||||||||||||||||||
| 88 | 4 | my $class = shift; | |||||||||||||||||||
| 89 | 4 | ▶ | unless (UNIVERSAL::can( $class, 'new' )) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | 4 | eval "require $class"; | |||||||||||||||||||
| 91 | 4 | ▶ | throw Pipeline::Config::LoadError( "error loading $class: $@" ) if $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | 0 | return $class; | |||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 1 | 1; | |||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | __END__ | ||||||||||||||||||||