File Coverage

blib/lib/Clustericious/Client/Meta.pm
Criterion Covered Total %
statement 35 48 72.9
branch 2 4 50.0
condition 2 4 50.0
subroutine 6 9 66.6
pod 7 7 100.0
total 52 72 72.2


line stmt bran cond sub pod time code
1             package Clustericious::Client::Meta;
2              
3 3     3   15 use strict;
  3         7  
  3         101  
4 3     3   18 use warnings;
  3         6  
  3         1512  
5              
6             # ABSTRACT: simple meta object for constructing clients
7             our $VERSION = '0.85'; # VERSION
8              
9             our %Routes; # hash from class name to array ref of routes.
10             our %RouteAttributes; # hash from class name to hash ref of attributes.
11             our %Objects; # hash from class name to array ref of objects.
12             our @CommonRoutes = ( [ "version" => '' ], [ "status" => '' ], [ "api" => '' ], [ "logtail" => '' ] );
13              
14              
15             sub add_route { # Keep track of routes that have are added.
16 9     9 1 172 my $class = shift;
17 9         10 my $for = shift; # e.g. Restmd::Client
18 9         18 my $route_name = shift; # same as $subname
19 9   100     29 my $route_doc = shift || '';
20              
21 9 100       9 if (my ($found) = grep { $_->[0] eq $route_name } @{ $Routes{$for} }) {
  31         66  
  9         21  
22 1         8 $found->[1] = $route_doc;
23 1         8 return;
24             }
25 8         9 push @{ $Routes{$for} }, [ $route_name => $route_doc ];
  8         35  
26             }
27              
28              
29             sub get_route_doc {
30 1     1 1 28 my $class = shift;
31 1         2 my $for = shift; # e.g. Restmd::Client
32 1         3 my $route_name = shift; # same as $subname
33 1         2 my ($found) = grep { $_->[0] eq $route_name } @{ $Routes{$for} };
  8         12  
  1         3  
34 1         8 return $found->[1];
35             }
36              
37              
38             sub add_route_attribute {
39 22     22 1 629 my $class = shift;
40 22         25 my $for = shift; # e.g. Restmd::Client
41 22         23 my $route_name = shift;
42 22         24 my $attr_name = shift;
43 22         23 my $attr_value = shift;
44 22         103 $RouteAttributes{$for}->{$route_name}{$attr_name} = $attr_value;
45             }
46              
47              
48             sub get_route_attribute {
49 30     30 1 853 my $class = shift;
50 30         33 my $for = shift; # e.g. Restmd::Client
51 30         41 my $route_name = shift;
52 30         47 my $attr_name = shift;
53 30         210 return $RouteAttributes{$for}->{$route_name}{$attr_name};
54             }
55              
56              
57             sub add_object {
58 0     0 1   my $class = shift;
59 0           my $for = shift;
60 0           my $obj_name = shift;
61 0   0       my $obj_doc = shift || '';
62 0           push @{ $Objects{$for} }, [ $obj_name => $obj_doc ];
  0            
63             }
64              
65              
66             sub routes {
67 0     0 1   my $class = shift;
68 0           my $for = shift;
69 0 0         return [ @CommonRoutes, @{$Routes{$for} || []}];
  0            
70             }
71              
72             sub objects {
73 0     0 1   my $class = shift;
74 0           my $for = shift;
75 0           return $Objects{$for};
76              
77             }
78              
79             1;
80              
81              
82              
83              
84             __END__