Package-New-0.09/ 0000755 0001750 0001750 00000000000 13622660400 013053 5 ustar mdavis mdavis Package-New-0.09/t/ 0000755 0001750 0001750 00000000000 13622660400 013316 5 ustar mdavis mdavis Package-New-0.09/t/004_dump.t 0000644 0001750 0001750 00000000652 13575072013 015042 0 ustar mdavis mdavis # -*- perl -*-
use strict;
use warnings;
use Test::More tests => 5;
use Devel::Hide qw(Data::Dumper);
BEGIN { use_ok( 'Package::New::Dump' ); }
my $object = Package::New::Dump->new(one=>{two=>{three=>{four=>{}}}});
isa_ok($object, 'Package::New::Dump');
isa_ok($object, 'Package::New');
my $value = $object->dump;
is($value, '', 'dump empty string');
my @value = $object->dump;
is(scalar(@value), 0, 'dump empty array');
Package-New-0.09/t/002_base.t 0000644 0001750 0001750 00000001677 13622651730 015017 0 ustar mdavis mdavis # -*- perl -*-
use strict;
use warnings;
use Test::More tests => 16;
BEGIN { use_ok( 'Package::New' ); }
{
my $object = My::Package->new(x=>1, y=>"a");
isa_ok($object, 'Package::New');
isa_ok($object, 'My::Package');
can_ok($object, qw{new initialize x y});
is($object->x, "1", "args work");
is($object->y, "a", "args work");
}
{
my $object = My::Package->new(x=>undef)->new(x=>1, y=>"a");
isa_ok($object, 'Package::New');
isa_ok($object, 'My::Package');
can_ok($object, qw{new initialize x y});
is($object->x, "1", "args work");
is($object->y, "a", "args work");
}
{
my $object = new My::Package x=>1, y=>"a";
isa_ok($object, 'Package::New');
isa_ok($object, 'My::Package');
can_ok($object, qw{new initialize x y});
is($object->x, "1", "args work");
is($object->y, "a", "args work");
}
{
package #Hide from CPAN
My::Package;
use base qw{Package::New};
sub x {shift->{"x"}};
sub y {shift->{"y"}};
1;
}
Package-New-0.09/t/001_load.t 0000644 0001750 0001750 00000001205 13575070161 015006 0 ustar mdavis mdavis # -*- perl -*-
use strict;
use warnings;
use Test::More tests => 13;
BEGIN { use_ok( 'Package::New' ); }
BEGIN { use_ok( 'Package::New::Dump' ); }
my $obj1 = Package::New->new(x=>1, y=>"a");
isa_ok ($obj1, 'Package::New');
isa_ok($obj1->new, 'Package::New');
can_ok($obj1, qw{new initialize});
is($obj1->{"x"}, "1", "args work");
is($obj1->{"y"}, "a", "args work");
my $obj2 = Package::New::Dump->new(x=>2, y=>"b");
isa_ok($obj2, 'Package::New::Dump');
isa_ok($obj2, 'Package::New');
isa_ok($obj2->new, 'Package::New::Dump');
can_ok($obj2, qw{new initialize dump});
is($obj2->{"x"}, "2", "args work");
is($obj2->{"y"}, "b", "args work");
Package-New-0.09/t/003_dump.t 0000644 0001750 0001750 00000003155 13622660325 015044 0 ustar mdavis mdavis # -*- perl -*-
use strict;
use warnings;
use Test::More tests => 17;
BEGIN { use_ok( 'Package::New::Dump' ); }
my $object = Bar->new(one=>{two=>{three=>{four=>{}}}});
isa_ok($object, 'Bar');
isa_ok($object, 'Foo');
isa_ok($object, 'Package::New::Dump');
isa_ok($object, 'Package::New');
can_ok($object, qw{new initialize dump});
can_ok($object, qw{bar});
can_ok($object, qw{baz});
is($object->bar, "baz", "object method");
is(Bar->bar, "baz", "class method");
is($object->baz, "buz", "object method");
is(Bar->baz, "buz", "class method");
{
my $dump = $object->dump(1);
diag($dump);
$dump =~ s/\s+//g; #white space compress
$dump =~ s/0x[0-9a-f]+/XXX/;
is($dump, q{$VAR1=bless({'one'=>'HASH(XXX)'},'Bar');});
}
{
my $dump = $object->dump();
diag($dump);
$dump =~ s/\s+//g; #white space compress
$dump =~ s/0x[0-9a-f]+/XXX/;
is($dump, q{$VAR1=bless({'one'=>{'two'=>'HASH(XXX)'}},'Bar');});
}
{
my $dump = $object->dump(undef);
diag($dump);
$dump =~ s/\s+//g; #white space compress
$dump =~ s/0x[0-9a-f]+/XXX/;
is($dump, q{$VAR1=bless({'one'=>{'two'=>'HASH(XXX)'}},'Bar');});
}
{
my $dump = $object->dump(2);
diag($dump);
$dump =~ s/\s+//g; #white space compress
$dump =~ s/0x[0-9a-f]+/XXX/;
is($dump, q{$VAR1=bless({'one'=>{'two'=>'HASH(XXX)'}},'Bar');});
}
{
my $dump = $object->dump(0);
diag($dump);
$dump =~ s/\s+//g; #white space compress
is($dump, q{$VAR1=bless({'one'=>{'two'=>{'three'=>{'four'=>{}}}}},'Bar');});
}
{
package #hide
Foo;
use base qw{Package::New::Dump};
sub bar {"baz"};
1;
}
{
package #hide
Bar;
use base qw{Foo};
sub baz {"buz"};
1;
}
Package-New-0.09/perl-Package-New.spec 0000644 0001750 0001750 00000003630 13622657770 016773 0 ustar mdavis mdavis Name: perl-Package-New
Version: 0.09
Release: 1%{?dist}
Summary: Simple base package from which to inherit
License: BSD
Group: Development/Libraries
URL: http://search.cpan.org/dist/Package-New/
Source0: http://search.cpan.org/CPAN/authors/id/M/MR/MRDVT/Package-New-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArch: noarch
BuildRequires: perl(ExtUtils::MakeMaker)
BuildRequires: perl(Devel::Hide)
BuildRequires: perl(Test::Simple) >= 0.44
Requires: perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version))
%description
The Package::New object provides a consistent object constructor for
objects.
%prep
%setup -q -n Package-New-%{version}
%build
%{__perl} Makefile.PL INSTALLDIRS=vendor
make %{?_smp_mflags}
%install
rm -rf $RPM_BUILD_ROOT
make pure_install PERL_INSTALL_ROOT=$RPM_BUILD_ROOT
find $RPM_BUILD_ROOT -type f -name .packlist -exec rm -f {} \;
find $RPM_BUILD_ROOT -depth -type d -exec rmdir {} 2>/dev/null \;
%{_fixperms} $RPM_BUILD_ROOT/*
%check
make test
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
%doc Changes LICENSE README Todo
%{perl_vendorlib}/*
%{_mandir}/man3/*
%changelog
*Thu Dec 03 2011 Michael R. Davis (mdavis@stopllc.com) 0.07-2
-CPAN did not symlink the package into the by_module tree.
*Thu Dec 02 2011 Michael R. Davis (mdavis@stopllc.com) 0.07-1
-Updated for version 0.07
*Wed Feb 23 2011 Michael R. Davis (mdavis@stopllc.com) 0.05-1
-Updated for version 0.05
*Wed Feb 23 2011 Michael R. Davis (mdavis@stopllc.com) 0.04-1
-Updated for version 0.04
*Sat Feb 05 2011 Michael R. Davis (mdavis@stopllc.com) 0.03-1
-Updated for version 0.03
*Fri Feb 04 2011 Michael R. Davis (mdavis@stopllc.com) 0.02-1
-Updated for version 0.02
*Fri Feb 04 2011 Michael R. Davis (mdavis@stopllc.com) 0.01-1
-Specfile autogenerated by cpanspec 1.78.
Package-New-0.09/Changes 0000644 0001750 0001750 00000001646 13622660200 014353 0 ustar mdavis mdavis Revision history for Perl module Package::New
0.09 2020-02-17
- Updated lib/Package/New.pm - fixed testing coverage issue
- Updated t/002_base.t and t/003_dump.t - added testing coverage
0.08 2019-12-14
- Updated t/001_load.t - Added test cases from cpancover.com
- Added t/004_dump.t - Added test cases from cpancover.com
- Updated lib/Package/New/Dump.pm - Slightly refactored dump method
0.07 2011-12-01
- Cleaned up for Fedora 16
0.06 2011-08-01
- Abandoned Fork
0.05_2 2011-02-24
- Documentation
0.05 2011-02-23
- Fixed issue with pod NAME which messed up CPAN indexer
0.04 2011-02-23
- Updated Documentation
- Added dump tests
- Disabled Data::Dumper export of Dumper
- Updated tests to use can_ok instead of $obj->can
0.03 2011-02-05
- Added package with dump method for testing
0.02 2011-02-04
- Documentation
0.01 2011-02-04
- original version; created by ExtUtils::ModuleMaker 0.51
Package-New-0.09/Todo 0000644 0001750 0001750 00000000070 13024005047 013674 0 ustar mdavis mdavis TODO list for Perl module Package::New
- Nothing yet
Package-New-0.09/lib/ 0000755 0001750 0001750 00000000000 13622660400 013621 5 ustar mdavis mdavis Package-New-0.09/lib/Package/ 0000755 0001750 0001750 00000000000 13622660400 015154 5 ustar mdavis mdavis Package-New-0.09/lib/Package/New.pm 0000644 0001750 0001750 00000005126 13622657754 016271 0 ustar mdavis mdavis package Package::New;
use strict;
use warnings;
our $VERSION='0.09';
=head1 NAME
Package::New - Simple base package from which to inherit
=head1 SYNOPSIS
package My::Package;
use base qw{Package::New}; #provides new and initialize
=head1 DESCRIPTION
The Package::New object provides a consistent constructor for objects.
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.
=head1 RECOMMENDATIONS
=head2 Sane defaults
I recommend that you have sane default for all of your object properties. I recommend using code like this.
sub myproperty {
my $self=shift;
$self->{"myproperty"}=shift if @_;
$self->{"myproperty"}="Default Value" unless defined $self->{"myproperty"};
return $self->{"myproperty"};
}
=head2 use strict and warnings
I recommend to always use strict, warnings and our version.
package My::Package;
use base qw{Package::New};
use strict;
use warnings;
our $VERSION='0.01';
=head2 Lazy Load where you can
I recommend Lazy Loading where you can.
sub mymethod {
my $self=shift;
$self->load unless $self->loaded;
return $self->{"mymethod"};
}
=head1 USAGE
=head1 CONSTRUCTOR
=head2 new
my $obj = Package::New->new(key=>$value, ...);
=cut
sub new {
my $this = shift;
my $class = ref($this) ? ref($this) : $this;
my $self = {};
bless $self, $class;
$self->initialize(@_);
return $self;
}
=head2 initialize
You can override this method in your package if you need to do something after construction. But, lazy loading may be a better option.
=cut
sub initialize {
my $self=shift;
%$self=@_;
}
=head1 BUGS
Log on RT and contact the author.
=head1 SUPPORT
DavisNetworks.com provides support services for all Perl applications including this package.
=head1 AUTHOR
Michael R. Davis
CPAN ID: MRDVT
DavisNetworks.com
http://www.DavisNetworks.com/
=head1 COPYRIGHT
This program is free software licensed under the...
The BSD License
The full text of the license can be found in the LICENSE file included with this module.
=head1 SEE ALSO
=head2 Building Blocks
L, L
=head2 Other Light Weight Base Objects Similar to Package::New
L, L, L, L, L
=head2 Heavy Base Objects - Drink the Kool-Aid
L, L, L, L, (as well as Moose-alikes L, L), L, L
=head2 Even more
L, L, L, L, L, L
=cut
1;
Package-New-0.09/lib/Package/New/ 0000755 0001750 0001750 00000000000 13622660400 015705 5 ustar mdavis mdavis Package-New-0.09/lib/Package/New/Dump.pm 0000644 0001750 0001750 00000002665 13575072746 017202 0 ustar mdavis mdavis package Package::New::Dump;
use base qw{Package::New};
use strict;
use warnings;
our $VERSION='0.08';
=head1 NAME
Package::New::Dump - Simple base package from which to inherit
=head1 SYNOPSIS
package My::Package;
use base qw{Package::New::Dump}; #provides new, initialize and dump
=head1 DESCRIPTION
The Package::New::Dump object provides a consistent object constructor for objects.
=head1 RECOMMENDATIONS
I recommend using this package only during development and reverting back to L when in full production
=head1 USAGE
=head1 CONSTRUCTOR
See L
=cut
=head1 METHODS
=head2 dump
Returns the object serialized by L
=cut
sub dump {
my $self = shift;
my $depth = shift;
$depth = 2 unless defined $depth;
local $@;
eval 'use Data::Dumper qw{}';
my $error = $@;
if ($error) {
return wantarray ? () : '';
} else {
my $d = Data::Dumper->new([$self]);
$d->Maxdepth($depth);
return $d->Dump;
}
}
=head1 BUGS
Log on RT and contact the author.
=head1 SUPPORT
DavisNetworks.com provides support services for all Perl applications including this package.
=head1 AUTHOR
Michael R. Davis
CPAN ID: MRDVT
DavisNetworks.com
http://www.DavisNetworks.com/
=head1 COPYRIGHT
This program is free software licensed under the...
The BSD License
The full text of the license can be found in the LICENSE file included with this module.
=head1 SEE ALSO
=cut
1;
Package-New-0.09/MANIFEST 0000644 0001750 0001750 00000000516 13622660400 014206 0 ustar mdavis mdavis MANIFEST
README
LICENSE
Todo
Changes
Makefile.PL
lib/Package/New.pm
lib/Package/New/Dump.pm
t/001_load.t
t/002_base.t
t/003_dump.t
t/004_dump.t
perl-Package-New.spec
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
Package-New-0.09/README 0000644 0001750 0001750 00000000276 13024005047 013734 0 ustar mdavis mdavis to install the module...
rpmbuild -ta tarball.tar.gz
rpm -Uhv file.rpm
perl Makefile.PL
make
make test
make install
If you are on a windows box you should use 'nmake' rather than 'make'.
Package-New-0.09/LICENSE 0000644 0001750 0001750 00000003011 13024005047 014047 0 ustar mdavis mdavis The BSD License
Copyright (c) 2011, Michael R. Davis
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
Neither the name of the Satellite Tracking of People, LLC nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
Package-New-0.09/Makefile.PL 0000644 0001750 0001750 00000000544 13575071662 015045 0 ustar mdavis mdavis use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Package::New',
VERSION_FROM => 'lib/Package/New.pm',
AUTHOR => 'Michael R. Davis (mdavis@stopllc.com)',
ABSTRACT_FROM=> 'lib/Package/New.pm',
PREREQ_PM => {
'Test::Simple' => 0.44,
'Devel::Hide' => 0,
},
);
Package-New-0.09/META.yml 0000664 0001750 0001750 00000001022 13622660400 014321 0 ustar mdavis mdavis ---
abstract: 'Simple base package from which to inherit'
author:
- 'Michael R. Davis (mdavis@stopllc.com)'
build_requires:
ExtUtils::MakeMaker: 0
configure_requires:
ExtUtils::MakeMaker: 0
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 6.68, CPAN::Meta::Converter version 2.120921'
license: unknown
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: Package-New
no_index:
directory:
- t
- inc
requires:
Devel::Hide: 0
Test::Simple: 0.44
version: 0.09
Package-New-0.09/META.json 0000664 0001750 0001750 00000001644 13622660400 014503 0 ustar mdavis mdavis {
"abstract" : "Simple base package from which to inherit",
"author" : [
"Michael R. Davis (mdavis@stopllc.com)"
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 6.68, CPAN::Meta::Converter version 2.120921",
"license" : [
"unknown"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "Package-New",
"no_index" : {
"directory" : [
"t",
"inc"
]
},
"prereqs" : {
"build" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"runtime" : {
"requires" : {
"Devel::Hide" : "0",
"Test::Simple" : "0.44"
}
}
},
"release_status" : "stable",
"version" : "0.09"
}