DBRIS/Offer.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 55 CC 4 SCAR 22.2
CC
4
Cov
0%
new
20.0
conditions
2.0
BEGIN
2.0
CRAP 9.2
1 package Travel::Routing::DE::DBRIS::Offer;
2  
3 use strict;
4 use warnings;
5 use 5.020;
6 use utf8;
7  
8 use parent 'Class::Accessor';
9  
10 our $VERSION = '0.18';
11  
12 Travel::Routing::DE::DBRIS::Offer->mk_ro_accessors(
13 qw(class name price price_unit is_upsell is_cross_sell needs_context));
14  
15 sub new {
16 my ( $obj, %opt ) = @_;
17  
18 my $json = $opt{json};
19  
20 my $ref = {
21 class => $json->{klasse} =~ s{KLASSE_}{}r,
22 name => $json->{name},
23 price => $json->{preis}{betrag},
24 price_unit => $json->{preis}{waehrung},
25 conditions => $json->{konditionsAnzeigen},
26 is_upsell => exists $json->{upsellInfos} ? 1 : 0,
27 is_cross_sell => exists $json->{crosssellInfos} ? 1 : 0,
28 };
29  
30 for my $relation ( @{ $json->{angebotsbeziehungList} // [] } ) {
31 for my $offer_ref ( @{ $relation->{referenzen} // [] } ) {
32 if ( $offer_ref->{referenzAngebotsoption} eq 'PFLICHT' ) {
33 $ref->{needs_context} = 1;
34 }
35 }
36 }
37  
38 bless( $ref, $obj );
39  
40 return $ref;
41 }
42  
43 sub conditions {
44 my ($self) = @_;
45  
46 return @{ $self->{conditions} // [] };
47 }
48  
49 1;