File Coverage

blib/lib/Beam/Runner/Command/run.pm
Criterion Covered Total %
statement 28 28 100.0
branch 4 4 100.0
condition 3 6 50.0
subroutine 7 7 100.0
pod 0 1 0.0
total 42 46 91.3


line stmt bran cond sub pod time code
1             package Beam::Runner::Command::run;
2             our $VERSION = '0.015';
3             # ABSTRACT: Run the given service with the given arguments
4              
5             #pod =head1 SYNOPSIS
6             #pod
7             #pod beam run []
8             #pod
9             #pod =head1 DESCRIPTION
10             #pod
11             #pod Run a service from the given container, passing in any arguments.
12             #pod
13             #pod =head1 SEE ALSO
14             #pod
15             #pod L, L, L
16             #pod
17             #pod =cut
18              
19 1     1   21914 use strict;
  1         2  
  1         28  
20 1     1   10 use warnings;
  1         2  
  1         24  
21 1     1   664 use Beam::Wire;
  1         407005  
  1         57  
22 1     1   14 use Path::Tiny qw( path );
  1         3  
  1         61  
23 1     1   7 use Scalar::Util qw( blessed );
  1         2  
  1         45  
24 1     1   475 use Beam::Runner::Util qw( find_container_path );
  1         4  
  1         215  
25              
26             sub run {
27 5     5 0 14513 my ( $class, $container, $service_name, @args ) = @_;
28 5         19 my $path = find_container_path( $container );
29 4         120 my $wire = Beam::Wire->new(
30             file => $path,
31             );
32              
33 4         105292 my $service = eval { $wire->get( $service_name ) };
  4         19  
34 4 100       8861 if ( $@ ) {
35 2 100 33     284 if ( blessed $@ && $@->isa( 'Beam::Wire::Exception::NotFound' ) && $@->name eq $service_name ) {
      66        
36 1         9 die sprintf qq{Could not find service "%s" in container "%s"\n},
37             $service_name, $path;
38             }
39 1         9 die sprintf qq{Could not load service "%s" in container "%s": %s\n}, $service_name, $path, $@;
40             }
41              
42 2         13 return $service->run( @args );
43             }
44              
45             1;
46              
47             __END__