| 1 | # vim: set ts=2 sts=2 sw=2 expandtab smarttab: | ||||||||||||
| 2 | # | ||||||||||||
| 3 | # This file is part of Config-MVP-BundleInspector | ||||||||||||
| 4 | # | ||||||||||||
| 5 | # This software is copyright (c) 2013 by Randy Stauner. | ||||||||||||
| 6 | # | ||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 9 | # | ||||||||||||
| 10 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | package Config::MVP::BundleInspector; | ||||||||||||
| 14 | { | ||||||||||||
| 15 | 2 | $Config::MVP::BundleInspector::VERSION = '0.001'; | |||||||||||
| 16 | } | ||||||||||||
| 17 | # git description: 5002d73 | ||||||||||||
| 18 | |||||||||||||
| 19 | 2 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | 2 | $Config::MVP::BundleInspector::AUTHORITY = 'cpan:RWSTAUNER'; | |||||||||||
| 21 | } | ||||||||||||
| 22 | # ABSTRACT: Determine prereqs and INI string from PluginBundles | ||||||||||||
| 23 | |||||||||||||
| 24 | 2 | ▶ | use Class::Load (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | |||||||||||||
| 26 | 2 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | 2 | ▶ | use MooseX::AttributeShortcuts; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | 2 | ▶ | use MooseX::Types::Moose qw( Str ArrayRef HashRef ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 29 | 2 | ▶ | use MooseX::Types::Perl qw( PackageName Identifier ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 30 | 2 | ▶ | use namespace::autoclean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 31 | |||||||||||||
| 32 | # lots of lazy builders for subclasses | ||||||||||||
| 33 | |||||||||||||
| 34 | |||||||||||||
| 35 | 2 | has bundle_class => ( | |||||||||||
| 36 | is => 'ro', | ||||||||||||
| 37 | isa => PackageName, | ||||||||||||
| 38 | required => 1, | ||||||||||||
| 39 | ); | ||||||||||||
| 40 | |||||||||||||
| 41 | |||||||||||||
| 42 | 2 | has bundle_method => ( | |||||||||||
| 43 | is => 'lazy', | ||||||||||||
| 44 | isa => Identifier, | ||||||||||||
| 45 | ); | ||||||||||||
| 46 | |||||||||||||
| 47 | 1 | ▶ | sub _build_bundle_method { | ||||||||||
|
Subroutine
_build_bundle_method: called CC=1 SCAR=0.0
| |||||||||||||
| 48 | 1 | 'mvp_bundle_config' | |||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | |||||||||||||
| 52 | 2 | has bundle_name => ( | |||||||||||
| 53 | is => 'lazy', | ||||||||||||
| 54 | isa => Str, | ||||||||||||
| 55 | ); | ||||||||||||
| 56 | |||||||||||||
| 57 | 3 | ▶ | sub _build_bundle_name { | ||||||||||
|
Subroutine
_build_bundle_name: called CC=1 SCAR=0.0
| |||||||||||||
| 58 | 3 | return $_[0]->bundle_class; | |||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | |||||||||||||
| 62 | 2 | has plugin_specs => ( | |||||||||||
| 63 | is => 'lazy', | ||||||||||||
| 64 | isa => ArrayRef, | ||||||||||||
| 65 | ); | ||||||||||||
| 66 | |||||||||||||
| 67 | 3 | ▶ | sub _build_plugin_specs { | ||||||||||
|
Subroutine
_build_plugin_specs: called CC=1 SCAR=0.0
| |||||||||||||
| 68 | 3 | my ($self) = @_; | |||||||||||
| 69 | 3 | my $class = $self->bundle_class; | |||||||||||
| 70 | 3 | my $method = $self->bundle_method; | |||||||||||
| 71 | |||||||||||||
| 72 | 3 | Class::Load::load_class($class); | |||||||||||
| 73 | |||||||||||||
| 74 | 3 | return $self->_plugin_specs_from_bundle_method($class, $method); | |||||||||||
| 75 | } | ||||||||||||
| 76 | |||||||||||||
| 77 | 3 | ▶ | sub _plugin_specs_from_bundle_method { | ||||||||||
|
Subroutine
_plugin_specs_from_bundle_method: called CC=1 SCAR=0.0
| |||||||||||||
| 78 | 3 | my ($self, $class, $method) = @_; | |||||||||||
| 79 | return [ | ||||||||||||
| 80 | 3 | $class->$method({ | |||||||||||
| 81 | name => $self->bundle_name, | ||||||||||||
| 82 | payload => {}, | ||||||||||||
| 83 | }) | ||||||||||||
| 84 | ]; | ||||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | |||||||||||||
| 88 | 2 | has prereqs => ( | |||||||||||
| 89 | is => 'lazy', | ||||||||||||
| 90 | isa => 'CPAN::Meta::Requirements', | ||||||||||||
| 91 | ); | ||||||||||||
| 92 | |||||||||||||
| 93 | 3 | ▶ | sub _build_prereqs { | ||||||||||
|
Subroutine
_build_prereqs: called CC=4 SCAR=13.9
| |||||||||||||
| 94 | 3 | my ($self) = @_; | |||||||||||
| 95 | |||||||||||||
| 96 | 3 | require CPAN::Meta::Requirements; | |||||||||||
| 97 | 3 | my $prereqs = CPAN::Meta::Requirements->new; | |||||||||||
| 98 | 3 | foreach my $spec ( @{ $self->plugin_specs } ){ | |||||||||||
| 99 | 10 | my (undef, $class, $payload) = @$spec; | |||||||||||
| 100 | 10 | ▶ | $payload ||= {}; | ||||||||||
|
Condition100%2/2
$payload ||= {}
MC/DC100%1/1
$payload ||= {}
$payload
Truth table100%2/2
A
A= $payload
| |||||||||||||
| 101 | 10 | ▶ | $prereqs->add_minimum($class => $payload->{':version'} || 0) | ||||||||||
|
Condition100%2/2
$payload->{':version'} || 0
MC/DC100%1/1
$payload->{':version'} || 0
$payload->{':version'}
Truth table100%2/2
A
A= $payload->{':version'}
| |||||||||||||
| 102 | } | ||||||||||||
| 103 | |||||||||||||
| 104 | 3 | return $prereqs; | |||||||||||
| 105 | } | ||||||||||||
| 106 | |||||||||||||
| 107 | |||||||||||||
| 108 | 2 | has ini_string => ( | |||||||||||
| 109 | is => 'lazy', | ||||||||||||
| 110 | isa => Str, | ||||||||||||
| 111 | ); | ||||||||||||
| 112 | |||||||||||||
| 113 | |||||||||||||
| 114 | 2 | has ini_opts => ( | |||||||||||
| 115 | is => 'lazy', | ||||||||||||
| 116 | isa => HashRef, | ||||||||||||
| 117 | ); | ||||||||||||
| 118 | |||||||||||||
| 119 | 2 | ▶ | sub _build_ini_opts { | ||||||||||
|
Subroutine
_build_ini_opts: called CC=1 SCAR=0.0
| |||||||||||||
| 120 | 2 | return {}; | |||||||||||
| 121 | } | ||||||||||||
| 122 | |||||||||||||
| 123 | 3 | ▶ | sub _build_ini_string { | ||||||||||
|
Subroutine
_build_ini_string: called CC=1 SCAR=0.0
| |||||||||||||
| 124 | 3 | my ($self) = @_; | |||||||||||
| 125 | |||||||||||||
| 126 | 3 | require Config::MVP::Writer::INI; | |||||||||||
| 127 | 3 | my $string = Config::MVP::Writer::INI->new($self->ini_opts) | |||||||||||
| 128 | ->ini_string($self->plugin_specs); | ||||||||||||
| 129 | |||||||||||||
| 130 | 3 | return $string; | |||||||||||
| 131 | } | ||||||||||||
| 132 | |||||||||||||
| 133 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 134 | 2 | 1; | |||||||||||
| 135 | |||||||||||||
| 136 | __END__ | ||||||||||||