AtD/Scores.pm

filter: Statementstmt 95.8% 46 / 48 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 75.0% 3 / 4 totaltotal 90.1% 64 / 71 CC 6 SCAR 5.8
CC
6
Cov
89%
START
3.1
has_server_exception
2.1
has_metrics
2.1
CRAP 1.8
« AtD/Results.pm ↑ Summary AtD/Exceptions.pm »
1 #
2 # This file is part of Lingua-AtD
3 #
4 # This software is copyright (c) 2011 by David L. Day.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 package Lingua::AtD::Scores;
10 4 $Lingua::AtD::Scores::VERSION = '1.160790';
11 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use Lingua::AtD::Metric;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Lingua::AtD::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Class::Std;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # ABSTRACT: Encapsulate conversion of XML from /stats call to Metric objects.
20  
21 {
22  
23 # Attributes
24 4 my %xml_of : ATTR( :init_arg<xml> :get<xml> );
25 4 my %server_exception_of : ATTR( :get<server_exception> );
26 4 my %metric_count_of : ATTR( :get<metric_count> :default<0> );
27 4 my %metrics_of : ATTR();
28  
29 1 ▶ sub START {
Subroutine START: called CC=3 SCAR=11.2
Pod undocumented
30 1 my ( $self, $ident, $arg_ref ) = @_;
31 1 my @atd_metrics = ();
32  
33 1 my $parser = XML::LibXML->new();
34 1 my $dom = $parser->load_xml( string => $xml_of{$ident} );
35  
36 # Check for server message. Not sure if stats will do this.
37 1 ▶ if ( $dom->exists('/results/message') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dom->exists("/results/message")) 0 1 1
38 0 $server_exception_of{$ident} = $dom->findvalue('/results/message');
39  
40 # TODO: Implement Exceptions
41 0 croak $server_exception_of{$ident};
42  
43 # Lingua::AtD::ServiceException->throw(
44 # service_message => $server_exception_of{$ident} );
45 }
46  
47 1 foreach my $metric_node ( $dom->findnodes('/scores/metric') ) {
48 9 my $atd_metric = Lingua::AtD::Metric->new(
49 {
50 key => $metric_node->findvalue('key'),
51 type => $metric_node->findvalue('type'),
52 value => $metric_node->findvalue('value'),
53 }
54 );
55 9 $metric_count_of{$ident} += 1;
56 9 push( @atd_metrics, $atd_metric );
57 }
58 1 $metrics_of{$ident} = [@atd_metrics];
59  
60 1 return;
61 }
62  
63 1 ▶ sub has_server_exception {
Subroutine has_server_exception: called CC=2 SCAR=7.2
Pod documented
64 1 my $self = shift;
65 1 ▶ return defined( $server_exception_of{ ident($self) } ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $server_exception_of{builtin::refaddr($self)} ? : 0 1 1
66 }
67  
68 2 ▶ sub has_metrics {
Subroutine has_metrics: called CC=2 SCAR=7.2
Pod documented
69 2 my $self = shift;
70 2 ▶ return defined( $metrics_of{ ident($self) } ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $metrics_of{builtin::refaddr($self)} ? : 2 0 2
71 }
72  
73 1 ▶ sub get_metrics {
Subroutine get_metrics: called CC=2 SCAR=7.1
Pod documented
74 1 my $self = shift;
75 return $self->has_metrics()
76 1 ▶ ? @{ $metrics_of{ ident($self) } }
Branch: 1 branch
BranchTrueFalseTotal
$self->has_metrics ? : 1 0 1
77 : undef;
78 }
79 }
80  
81 4 1; # Magic true value required at end of module
82  
83 __END__
« AtD/Results.pm ↑ Summary AtD/Exceptions.pm »