lib/Myriad/API.pm

filter: Statementstmt 66.6% 4 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 75.0% 6 / 8 CC 1 SCAR 1.4
CC
1
Cov
67%
BEGIN
1.3
BEGIN
1.0
CRAP 1.1
« lib/Myriad/Util/UUID.pm ↑ Summary lib/Myriad/Registry.pm »
1 package Myriad::API;
2  
3 3 ▶use Myriad::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 our $VERSION = '1.001'; # VERSION
6 our $AUTHORITY = 'cpan:DERIV'; # AUTHORITY
7  
8 =encoding utf8
9  
10 =head1 NAME
11  
12 Myriad::API - provides an API for Myriad services
13  
14 =head1 SYNOPSIS
15  
16 =head1 DESCRIPTION
17  
18 Used internally within L<Myriad> services for providing access to
19 storage, subscription and RPC behaviour.
20  
21 =cut
22  
23 0 ▶use Myriad::Config;
Subroutine BEGIN: called CC=1 SCAR=2.6
24 use Myriad::Service::Remote;
25 use Myriad::Service::Storage;
26  
27 has $myriad;
28 has $service_name;
29 has $storage;
30 has $config;
31  
32 =head1 METHODS
33  
34 =cut
35  
36 BUILD (%args) {
37 weaken($myriad = delete $args{myriad});
38 $service_name = delete $args{service_name} // die 'need a service name';
39 $config = delete $args{config} // {};
40 $storage = Myriad::Service::Storage->new(
41 prefix => $service_name,
42 storage => $myriad->storage
43 );
44 }
45  
46 =head2 storage
47  
48 Returns a L<Myriad::Role::Storage>-compatible instance for interacting with storage.
49  
50 =cut
51  
52 method storage () { $storage }
53  
54 =head2 service_by_name
55  
56 Returns a service proxy instance for the given service name.
57  
58 This can be used to call RPC methods and act on subscriptions.
59  
60 =cut
61  
62 method service_by_name ($name) {
63 return Myriad::Service::Remote->new(
64 myriad => $myriad,
65 service_name => $myriad->registry->make_service_name($name),
66 local_service_name => $service_name
67 );
68 }
69  
70  
71 =head2 config
72  
73 Returns a L<Ryu::Observable> that hold the value of the configuration.
74  
75 =cut
76  
77 method config ($key) {
78 my $pkg = caller;
79 if($Myriad::Config::SERVICES_CONFIG{$pkg}->{$key}) {
80 return $config->{$key};
81 }
82 Myriad::Exception::Config::UnregisteredConfig->throw(reason => "$key is not registred by service $service_name");
83 }
84  
85 1;
86  
87 __END__
« lib/Myriad/Util/UUID.pm ↑ Summary lib/Myriad/Registry.pm »