Articulate/Serialisation.pm

filter: Statementstmt 61.5% 16 / 26 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 100% 1 / 1 totaltotal 55.0% 22 / 40 SCAR 20.9
CC
5
Cov
50%
serialise
30.0
__ANON__
2.0
BEGIN
1.0
CRAP 8.1
« Articulate/Location.pm ↑ Summary Articulate/Response.pm »
1 package Articulate::Serialisation;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 with 'Articulate::Role::Component';
8  
9 4 ▶use Articulate::Syntax qw(instantiate_array);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Articulate::Serialisation - transform a data structure into user-facing output.
14  
15 =head1 DESCRIPTION
16  
17 use Articulate::Serialisation;
18 my $html = serialisation->serialise($response_object);
19  
20 Go through all the defined serialisers and have them attempt to serialise the response object. The first defined result will be returned. The result be of any data type, although in practice the purpose is to use a string.
21  
22 Provides a serialisation function which creates an instance of this class.
23  
24 =head1 FUNCTION
25  
26 =head3 serialisers
27  
28 This is an arrayref of serialisers, each of whom should provide serialise functions.
29  
30 =cut
31  
32 has serialisers => (
33 is => 'rw',
34 0 ▶ default => sub{ [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 3 ▶ coerce => sub { instantiate_array (@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
36 4 );
37  
38 =head1 FUNCTION
39  
40 =head3 serialise
41  
42 my $html = $serialisation->serialise($response_object);
43  
44 Sends to each of the C<serialisers> in turn. If any of them return a defined value, returns that value immediately. Otherwise, returns C<undef>.
45  
46 =cut
47  
48 sub serialise {
49 0 ▶ my $self = shift;
Subroutine serialise: not called CC=5 SCAR=34.0
Pod documented
50 0 my $response = shift;
51 # If the user has done templating themselves already, all well and good.
52 0 ▶ return $response unless ref $response;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $response 0 0 0
53 0 my $text;
54 0 foreach my $serialiser (@{ $self->serialisers }) {
55 0 ▶ $serialiser->app($self->app) if $serialiser->can('app'); # or does Articulate::Role::Component?
Branch: 1 branch
BranchTrueFalseTotal
if $serialiser->can("app") 0 0 0
56 0 ▶ return $text if defined ( $text = $serialiser->serialise($response) );
Branch: 1 branch
BranchTrueFalseTotal
if defined($text = $serialiser->serialise($response)) 0 0 0
57 }
58 0 return undef;
59 }
60  
61 4 1;
« Articulate/Location.pm ↑ Summary Articulate/Response.pm »