File Coverage

blib/lib/PONAPI/Builder/Links.pm
Criterion Covered Total %
statement 18 18 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 0 3 0.0
total 25 28 89.2


line stmt bran cond sub pod time code
1             # ABSTRACT: document builder - links
2             package PONAPI::Builder::Links;
3              
4 34     34   168381 use Moose;
  34         328004  
  34         235  
5              
6             with 'PONAPI::Builder',
7             'PONAPI::Builder::Role::HasMeta';
8              
9             has _links => (
10             init_arg => undef,
11             traits => [ 'Hash' ],
12             is => 'ro',
13             isa => 'HashRef',
14             lazy => 1,
15             default => sub { +{} },
16             handles => {
17             'has_links' => 'count',
18             'has_link' => 'exists',
19             'get_link' => 'get',
20             # private ...
21             '_add_link' => 'set',
22             '_keys_links' => 'keys',
23             }
24             );
25              
26             sub add_link {
27 426     426 0 853 my ( $self, $rel, $url ) = @_;
28 426         19601 $self->_add_link( $rel => $url );
29 426         1056 return $self;
30             }
31              
32             sub add_links {
33 25     25 0 107 my ( $self, %links ) = @_;
34 25         156 $self->add_link( $_, $links{ $_ } ) foreach keys %links;
35 25         134 return $self;
36             }
37              
38             sub build {
39 696     696 0 1035 my $self = $_[0];
40 696         1071 my $result = {};
41              
42 696         31257 foreach my $key ( $self->_keys_links ) {
43 943         41553 $result->{ $key } = $self->get_link( $key );
44             }
45              
46 696 100       32340 $result->{meta} = $self->_meta if $self->has_meta;
47              
48 696         2188 return $result;
49             }
50              
51             __PACKAGE__->meta->make_immutable;
52 34     34   227176 no Moose; 1;
  34         74  
  34         178  
53              
54             __END__
55              
56             =pod
57              
58             =encoding UTF-8
59              
60             =head1 NAME
61              
62             PONAPI::Builder::Links - document builder - links
63              
64             =head1 VERSION
65              
66             version 0.002006
67              
68             =head1 AUTHORS
69              
70             =over 4
71              
72             =item *
73              
74             Mickey Nasriachi <mickey@cpan.org>
75              
76             =item *
77              
78             Stevan Little <stevan@cpan.org>
79              
80             =item *
81              
82             Brian Fraser <hugmeir@cpan.org>
83              
84             =back
85              
86             =head1 COPYRIGHT AND LICENSE
87              
88             This software is copyright (c) 2016 by Mickey Nasriachi, Stevan Little, Brian Fraser.
89              
90             This is free software; you can redistribute it and/or modify it under
91             the same terms as the Perl 5 programming language system itself.
92              
93             =cut