| 1 | package DBIx::Class::Migration::ShareDirBuilder; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 9 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 9 | ▶ | use version 0.77; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 9 | ▶ | use File::ShareDir::ProjectDistDir 0.3.1 (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 9 | ▶ | use Log::Any '$log', default_adapter => 'Stderr'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 9 | ▶ | use Carp 'croak'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 9 | ▶ | use DBIx::Class::Migration::Types -all; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 0 | ▶ | sub _log_die { | ||||||||||||||||||
|
Subroutine
_log_die: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 11 | 0 | my ($msg) = @_; | |||||||||||||||||||
| 12 | 0 | $log->error($msg); | |||||||||||||||||||
| 13 | 0 | croak $msg; | |||||||||||||||||||
| 14 | } | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | has log => ( | ||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||
| 18 | isa => InstanceOf['Log::Any::Proxy'], | ||||||||||||||||||||
| 19 | 1 | ▶ | default => sub { Log::Any->get_logger( category => 'DBIx::Class::Migration') }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 9 | ); | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 9 | has schema_class => ( | |||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||
| 24 | isa => Str, | ||||||||||||||||||||
| 25 | required => 1); | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 1 | ▶ | sub filename_from_class { | ||||||||||||||||||
|
Subroutine
filename_from_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 28 | 1 | (my $filename_part = shift) =~s/::/\//g; | |||||||||||||||||||
| 29 | 1 | return $INC{$filename_part.".pm"}; | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 1 | ▶ | sub class_to_distname { | ||||||||||||||||||
|
Subroutine
class_to_distname: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 33 | 1 | (my $dist = shift) =~s/::/-/g; | |||||||||||||||||||
| 34 | 1 | return $dist; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 1 | ▶ | sub build { | ||||||||||||||||||
|
Subroutine
build: called CC=5 SCAR=19.1
Pod
undocumented
| |||||||||||||||||||||
| 38 | 1 | my $given_class = my $class = shift->schema_class; | |||||||||||||||||||
| 39 | 1 | File::ShareDir::ProjectDistDir->import('dist_dir', | |||||||||||||||||||
| 40 | filename => filename_from_class($class)); | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 1 | my $sharedir; | |||||||||||||||||||
| 43 | 1 | ▶ | while($class) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 1 | ▶ | last if $sharedir = eval { dist_dir( class_to_distname($class) ) }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 0 | ▶ | last unless $class =~s/::[^:]+$//; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 1 | ▶ | return $sharedir || _log_die "Can't find a share for $given_class"; | ||||||||||||||||||
|
Condition33%1/3
$sharedir || _log_die("Can't find a share for $given_class")
MC/DC0%0/2
$sharedir || _log_die("Can't find a share for $given_class")
$sharedir
_log_die("Can't find a share for $given_class")
Truth table33%1/3
A || B
A= $sharedirB= _log_die("Can't find a share for $given_class")
| |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 9 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =head1 NAME | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | DBIx::Class::Migration::ShareDirBuilder - Build a target_dir in /share | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | =head1 SYNOPSIS | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | use DBIx::Class::Migration::ShareDirBuilder; | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | =head1 DESCRIPTION | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | This is a utility class that build the path to a distribution's C</share> | ||||||||||||||||||||
| 65 | directory, whether the distribution is installed (via C<make install> or if | ||||||||||||||||||||
| 66 | it is in development. | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | This probably isn't really user servicable, although if you need to make a | ||||||||||||||||||||
| 69 | custom C<target_dir> builder, you could look at this for example. | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | =head1 SEE ALSO | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | L<DBIx::Class::Migration>. | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | =head1 AUTHOR | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | See L<DBIx::Class::Migration> for author information | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | See L<DBIx::Class::Migration> for copyright and license information | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =cut | ||||||||||||||||||||
| 84 | |||||||||||||||||||||