lib/Finance/Loan/Private.pm

filter: Statementstmt 55.5% 15 / 27 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 100% 2 / 2 totaltotal 60.0% 21 / 35 CC 1 SCAR 2.9
CC
1
Cov
56%
premium
2.0
sorter
2.0
BEGIN
1.0
CRAP 1.3
« script/privateloan.pl ↑ Summary
1 package Finance::Loan::Private;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 our @EXPORT_OK=qw(premium sorter);
8  
9 =head1 NAME
10  
11 Finance::Loan::Private - Private loan under UK tax law.
12  
13 =head1 VERSION
14  
15 Version 0.01
16  
17 =cut
18  
19 2 our $VERSION = '0.01';
20  
21  
22 =head1 SYNOPSIS
23  
24 This script calculates the repayment schedule and tax deductions for a private loan under UK tax law.
25  
26 Perhaps a little code snippet.
27  
28 use Finance::Loan::Private;
29  
30 my $foo = Finance::Loan::Private->new();
31 ...
32  
33 =head1 EXPORT
34  
35 premium
36  
37 =head1 SUBROUTINES/METHODS
38  
39 =head2 premium($principal, $rate, $years)
40  
41 Calculates a conventional monthly mortgage premium. The calculated figure is slightly too high for our
42 purposes as it does not take account of the tax deductions.
43  
44 =over
45  
46 =item $principal
47  
48 The amount of the loan.
49  
50 =item $rate
51  
52 The interest rate as a percentage.
53  
54 =item $years
55  
56 The period of the loan in years
57  
58 =item Returns
59  
60 A monthly premium
61  
62 =back
63  
64 =cut
65  
66 0 ▶sub premium {
Subroutine premium: not called CC=1 SCAR=6.9
Pod documented
67 0 my $principal= shift;
68 0 my $rate = shift;
69 0 my $years = shift;
70 0 my $periods = 12*$years;
71 0 my $r = $rate/1200.0;
72 0 my $logr1 = log($r+1.0);
73 0 my $mult = exp($periods*$logr1);
74 0 my $payment = $r*$mult*$principal/($mult-1);
75 0 return $payment;
76 }
77  
78  
79 =head2 sorter($list)
80  
81 Sorts a list of hashrefs each of which contains a 'date' key. The value of the date key is a
82 ISO8601 date in the form yyyy-mm-dd.
83 Used for sorting lists of advances on the loan, changes of tax rate etc.
84  
85 =over
86  
87 =item $list
88  
89 An arrayref of hashrefs. Each hashref must contain a 'date' key whose value is a ISO8601 date.
90  
91 =item Returns
92  
93 A list (not a list ref) of sorted hashref.
94  
95 =back
96  
97 =cut
98  
99 0 ▶sub sorter {
Subroutine sorter: not called CC=1 SCAR=6.9
Pod documented
100 0 my $list = shift;
101 0 return sort {($a->{date} cmp $b->{date});} @$list;
102 }
103  
104 =head1 AUTHOR
105  
106 Raphael Mankin, C<< <rapmankin at cpan.org> >>
107  
108 =head1 BUGS
109  
110 Please report any bugs or feature requests to C<bug-finance-loan-private at rt.cpan.org>, or through
111 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Finance-Loan-Private>. I will be notified, and then you'll
112 automatically be notified of progress on your bug as I make changes.
113  
114  
115  
116  
117 =head1 SUPPORT
118  
119 You can find documentation for this module with the perldoc command.
120  
121 perldoc Finance::Loan::Private
122  
123  
124 You can also look for information at:
125  
126 =over 4
127  
128 =item * RT: CPAN's request tracker
129  
130 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Finance-Loan-Private>
131  
132 =item * AnnoCPAN: Annotated CPAN documentation
133  
134 L<http://annocpan.org/dist/Finance-Loan-Private>
135  
136 =item * CPAN Ratings
137  
138 L<http://cpanratings.perl.org/d/Finance-Loan-Private>
139  
140 =item * Search CPAN
141  
142 L<http://search.cpan.org/dist/Finance-Loan-Private/>
143  
144 =back
145  
146  
147 =head1 ACKNOWLEDGEMENTS
148  
149  
150 =head1 LICENSE AND COPYRIGHT
151  
152 Copyright 2012 Raphael Mankin.
153  
154 This program is free software; you can redistribute it and/or modify it
155 under the terms of either: the GNU General Public License as published
156 by the Free Software Foundation; or the Artistic License.
157  
158 See http://dev.perl.org/licenses/ for more information.
159  
160  
161 =cut
162  
163 2 1; # End of Finance::Loan::Private
« script/privateloan.pl ↑ Summary