File Coverage

blib/lib/Interchange6/Cart/Cost.pm
Criterion Covered Total %
statement 11 11 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 15 15 100.0


line stmt bran cond sub pod time code
1             package Interchange6::Cart::Cost;
2              
3 6     6   34037 use Interchange6::Types -types;
  6         10  
  6         48  
4              
5 6     6   24142 use Moo;
  6         15786  
  6         52  
6 6     6   4429 use namespace::clean;
  6         16216  
  6         44  
7              
8             =head1 NAME
9              
10             Interchange6::Cart::Cost - Cart cost class for Interchange6 Shop Machine
11              
12             =head1 DESCRIPTION
13              
14             Cart cost class for L.
15              
16             =head1 ATTRIBUTES
17              
18             =head2 id
19              
20             Cart id can be used for subclasses, e.g. primary key value for cart or product costs in the database.
21              
22             =cut
23              
24             has id => (
25             is => 'ro',
26             isa => Int,
27             );
28              
29             =head2 name
30              
31             Unique name is required.
32              
33             =cut
34              
35             has name => (
36             is => 'ro',
37             isa => NonEmptyStr,
38             required => 1,
39             );
40              
41             =head2 label
42              
43             Label for display. Default is same value as label.
44              
45             =cut
46              
47             has label => (
48             is => 'lazy',
49             isa => NonEmptyStr,
50             );
51              
52             sub _build_label {
53 1     1   104265 my $self = shift;
54 1         36 return $self->name;
55             };
56              
57             =head2 relative
58              
59             Boolean defaults to 0. If true then L is relative to L. If false then L is an absolute cost.
60              
61             =cut
62              
63             has relative => (
64             is => 'ro',
65             isa => Defined & Bool,
66             default => 0,
67             );
68              
69             =head2 inclusive
70              
71             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.
72              
73             =cut
74              
75             has inclusive => (
76             is => 'ro',
77             isa => Defined & Bool,
78             default => 0,
79             );
80              
81             =head2 compound
82              
83             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.
84              
85             Using L along with L makes no sense and no guarantee is
86             given as to what the result might be.
87              
88             =cut
89              
90             has compound => (
91             is => 'ro',
92             isa => Defined & Bool,
93             default => 0,
94             );
95              
96             =head2 amount
97              
98             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
99              
100             =cut
101              
102             has amount => (
103             is => 'ro',
104             isa => Defined & Num,
105             required => 1,
106             );
107              
108             =head2 current_amount
109              
110             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.
111              
112             =over
113              
114             =item Writer: C
115              
116             =back
117              
118             =cut
119              
120             has current_amount => (
121             is => 'ro',
122             isa => Num,
123             coerce => sub { defined $_[0] && sprintf( "%.2f", $_[0] ) },
124             writer => 'set_current_amount',
125             );
126              
127             1;