File Coverage

blib/lib/Package/New.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition 1 3 33.3
subroutine 4 4 100.0
pod 2 2 100.0
total 21 23 91.3


line stmt bran cond sub pod time code
1             package Package::New;
2 3     3   51145 use strict;
  3         8  
  3         114  
3 3     3   16 use warnings;
  3         6  
  3         528  
4              
5             our $VERSION='0.07';
6              
7             =head1 NAME
8              
9             Package::New - Simple base package from which to inherit
10              
11             =head1 SYNOPSIS
12              
13             package My::Package;
14             use base qw{Package::New}; #provides new and initialize
15              
16             =head1 DESCRIPTION
17              
18             The Package::New object provides a consistent constructor for objects.
19              
20             I find that I always need these two methods in every package that I build. I plan to use this package as the base for all of my CPAN packages.
21              
22             =head1 RECOMMENDATIONS
23              
24             =head2 Sane defaults
25              
26             I recommend that you have sane default for all of your object properties. I recommend using code like this.
27              
28             sub myproperty {
29             my $self=shift;
30             $self->{"myproperty"}=shift if @_;
31             $self->{"myproperty"}="Default Value" unless defined $self->{"myproperty"};
32             return $self->{"myproperty"};
33             }
34              
35             =head2 use strict and warnings
36              
37             I recommend to always use strict, warnings and our version.
38              
39             package My::Package;
40             use base qw{Package::New};
41             use strict;
42             use warnings;
43             our $VERSION='0.01';
44              
45             =head2 Lazy Load where you can
46              
47             I recommend Lazy Loading where you can.
48              
49             sub mymethod {
50             my $self=shift;
51             $self->load unless $self->loaded;
52             return $self->{"mymethod"};
53             }
54              
55             =head1 USAGE
56              
57             =head1 CONSTRUCTOR
58              
59             =head2 new
60              
61             my $obj = Package::New->new(key=>$value, ...);
62              
63             =cut
64              
65             sub new {
66 4     4 1 19266 my $this=shift;
67 4   33     35 my $class=ref($this) || $this;
68 4         14 my $self={};
69 4         13 bless $self, $class;
70 4         40 $self->initialize(@_);
71 4         16 return $self;
72             }
73              
74             =head2 initialize
75              
76             You can override this method in your package if you need to do something after construction. But, lazy loading may be a better option.
77              
78             =cut
79              
80             sub initialize {
81 4     4 1 11 my $self=shift;
82 4         47 %$self=@_;
83             }
84              
85             =head1 BUGS
86              
87             Log on RT and contact the author.
88              
89             =head1 SUPPORT
90              
91             DavisNetworks.com provides support services for all Perl applications including this package.
92              
93             =head1 AUTHOR
94              
95             Michael R. Davis
96             CPAN ID: MRDVT
97             DavisNetworks.com
98             http://www.DavisNetworks.com/
99              
100             =head1 COPYRIGHT
101              
102             This program is free software licensed under the...
103              
104             The BSD License
105              
106             The full text of the license can be found in the LICENSE file included with this module.
107              
108             =head1 SEE ALSO
109              
110             =head2 Building Blocks
111              
112             L, L
113              
114             =head2 Other Light Weight Base Objects Similar to Package::New
115              
116             L, L, L, L
117              
118             =head2 Heavy Base Objects - Drink the Kool-Aid
119              
120             L, (as well as Moose-alikes L, L), L, L, L, L
121              
122             =head2 Even more
123              
124             L, L, L, L, L, L
125              
126             =cut
127              
128             1;