File Coverage

blib/lib/Math/Util/CalculatedValue/Validatable.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Math::Util::CalculatedValue::Validatable;
2              
3 1     1   23207 use Moose;
  0            
  0            
4              
5             use MooseX::NonMoose;
6             extends 'Math::Util::CalculatedValue';
7             with 'MooseX::Role::Validatable';
8              
9             =head1 NAME
10              
11             Math::Util::CalculatedValue::Validatable - math adjustment, which can containe another adjustments with validation
12              
13             =head1 VERSION
14              
15             Version 0.01
16              
17             =head1 DESCRIPTION
18              
19             Represents an adjustment to a value (which can contain additional adjustments) with validation.
20              
21             =cut
22              
23             our $VERSION = '0.01';
24              
25             =head1 SYNOPSIS
26              
27             my $tid = Math::Util::CalculatedValue::Validatable->new({
28             name => 'time_in_days',
29             description => 'Duration in days',
30             set_by => 'Contract',
31             base_amount => 0,
32             });
33              
34             my $tiy = Math::Util::CalculatedValue::Validatable->new({
35             name => 'time_in_years',
36             description => 'Duration in years',
37             set_by => 'Contract',
38             base_amount => 1,
39             });
40              
41             my $dpy = Math::Util::CalculatedValue::Validatable->new({
42             name => 'days_per_year',
43             description => 'days in a year',
44             set_by => 'Contract',
45             base_amount => 365,
46             });
47              
48             $tid->include_adjustment('reset', $tiy);
49             $tid->include_adjustment('multiply', $dpy);
50              
51             print $tid->amount;
52              
53              
54             =head2 BUILD
55              
56             Bulder args to add validation method
57              
58             =cut
59              
60             sub BUILD {
61             my $self = shift;
62             $self->{validation_methods} = [qw(_validate_all_sub_adjustments)];
63             return;
64             }
65              
66             sub _validate_all_sub_adjustments {
67             my $self = shift;
68              
69             my @errors;
70             foreach my $cv (map { $_->[1] } @{$self->adjustments}) {
71             push @errors, $cv->all_errors unless ($cv->confirm_validity);
72             }
73              
74             return @errors;
75             }
76              
77             =head1 AUTHOR
78              
79             binary.com, C<< <rakesh at binary.com> >>
80              
81             =head1 BUGS
82              
83             Please report any bugs or feature requests to C<bug-math-util-calculatedvalue at rt.cpan.org>, or through
84             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Math-Util-CalculatedValue>. I will be notified, and then you'll
85             automatically be notified of progress on your bug as I make changes.
86              
87              
88             =head1 SUPPORT
89              
90             You can find documentation for this module with the perldoc command.
91              
92             perldoc Math::Util::CalculatedValue
93              
94              
95             You can also look for information at:
96              
97             =over 4
98              
99             =item * RT: CPAN's request tracker (report bugs here)
100              
101             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Math-Util-CalculatedValue>
102              
103             =item * AnnoCPAN: Annotated CPAN documentation
104              
105             L<http://annocpan.org/dist/Math-Util-CalculatedValue>
106              
107             =item * CPAN Ratings
108              
109             L<http://cpanratings.perl.org/d/Math-Util-CalculatedValue>
110              
111             =item * Search CPAN
112              
113             L<http://search.cpan.org/dist/Math-Util-CalculatedValue/>
114              
115             =back
116              
117              
118             =head1 ACKNOWLEDGEMENTS
119              
120              
121             =head1 LICENSE AND COPYRIGHT
122              
123             Copyright 2014 binary.com.
124              
125             This program is free software; you can redistribute it and/or modify it
126             under the terms of the the Artistic License (2.0). You may obtain a
127             copy of the full license at:
128              
129             L<http://www.perlfoundation.org/artistic_license_2_0>
130              
131             Any use, modification, and distribution of the Standard or Modified
132             Versions is governed by this Artistic License. By using, modifying or
133             distributing the Package, you accept this license. Do not use, modify,
134             or distribute the Package, if you do not accept this license.
135              
136             If your Modified Version has been derived from a Modified Version made
137             by someone other than you, you are nevertheless required to ensure that
138             your Modified Version complies with the requirements of this license.
139              
140             This license does not grant you the right to use any trademark, service
141             mark, tradename, or logo of the Copyright Holder.
142              
143             This license includes the non-exclusive, worldwide, free-of-charge
144             patent license to make, have made, use, offer to sell, sell, import and
145             otherwise transfer the Package with respect to any patent claims
146             licensable by the Copyright Holder that are necessarily infringed by the
147             Package. If you institute patent litigation (including a cross-claim or
148             counterclaim) against any party alleging that the Package constitutes
149             direct or contributory patent infringement, then this Artistic License
150             to you shall terminate on the date that such litigation is filed.
151              
152             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
153             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
154             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
155             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
156             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
157             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
158             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
159             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
160              
161              
162             =cut
163              
164             no Moose;
165              
166             1; # End of Math::Util::CalculatedValue::Validatable