File Coverage

blib/lib/Interchange6/Cart/Cost.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 23 23 100.0


line stmt bran cond sub pod time code
1             # Interchange6::Cart::Cost - Interchange6 cart cost class
2              
3             package Interchange6::Cart::Cost;
4              
5 5     5   47731 use strict;
  5         9  
  5         121  
6 5     5   1428 use Moo;
  5         28334  
  5         29  
7 5     5   5364 use Types::Standard qw/Bool Defined Int Num/;
  5         132942  
  5         46  
8 5     5   6278 use Types::Common::String qw/NonEmptyStr/;
  5         80263  
  5         47  
9              
10 5     5   3267 use namespace::clean;
  5         22264  
  5         28  
11              
12             =head1 NAME
13              
14             Interchange6::Cart::Cost - Cart cost class for Interchange6 Shop Machine
15              
16             =head1 DESCRIPTION
17              
18             Cart cost class for L.
19              
20             =head1 ATTRIBUTES
21              
22             =head2 id
23              
24             Cart id can be used for subclasses, e.g. primary key value for cart or product costs in the database.
25              
26             =cut
27              
28             has id => (
29             is => 'ro',
30             isa => Int,
31             );
32              
33             =head2 name
34              
35             Unique name is required.
36              
37             =cut
38              
39             has name => (
40             is => 'ro',
41             isa => NonEmptyStr,
42             required => 1,
43             );
44              
45             =head2 label
46              
47             Label for display. Default is same value as label.
48              
49             =cut
50              
51             has label => (
52             is => 'lazy',
53             isa => NonEmptyStr,
54             );
55              
56             sub _build_label {
57 1     1   28063 my $self = shift;
58 1         27 return $self->name;
59             };
60              
61             =head2 relative
62              
63             Boolean defaults to 0. If true then L is relative to L. If false then L is an absolute cost.
64              
65             =cut
66              
67             has relative => (
68             is => 'ro',
69             isa => Defined & Bool,
70             default => 0,
71             );
72              
73             =head2 inclusive
74              
75             Boolean defaults to 0. If true signifies that the cost is already included in the price for example to calculate the tax component for gross prices.
76              
77             =cut
78              
79             has inclusive => (
80             is => 'ro',
81             isa => Defined & Bool,
82             default => 0,
83             );
84              
85             =head2 compound
86              
87             Boolean defaults to 0. If true signifies that any following costs should be applied to the modified price B this cost has been applied. This might be used for such things as discounts which are applied before taxes are applied to the modified price.
88              
89             Using L along with L makes no sense and no guarantee is
90             given as to what the result might be.
91              
92             =cut
93              
94             has compound => (
95             is => 'ro',
96             isa => Defined & Bool,
97             default => 0,
98             );
99              
100             =head2 amount
101              
102             Required amount of the cost. This is the absolute cost unless L is true in which case it is relative to the L. For example for a tax of 8% amount should be set to 0.08
103              
104             =cut
105              
106             has amount => (
107             is => 'ro',
108             isa => Defined & Num,
109             required => 1,
110             );
111              
112             =head2 current_amount
113              
114             Calculated current amount of cost. Unless L is true this will be the same as L. If L is true then this is value is recalulated whenever C is called on the object.
115              
116             =over
117              
118             =item Writer: C
119              
120             =back
121              
122             =cut
123              
124             has current_amount => (
125             is => 'ro',
126             isa => Num,
127             coerce => sub { defined $_[0] && sprintf( "%.2f", $_[0] ) },
128             writer => 'set_current_amount',
129             );
130              
131             1;