diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..94b147b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,41 @@ +# DO NOT EDIT +# +# This .travis.yml file generated by Zilla::Dist. To upgrade it, run: +# +# > make update +# + +language: perl + +perl: +- '5.18' +- '5.16' +- '5.14' +- '5.12' +- '5.10' +- '5.8' + +install: +- cpanm --quiet --notest + Devel::Cover::Report::Coveralls + +script: +- PERL5OPT=-MDevel::Cover=-coverage,statement,branch,condition,path,subroutine + prove -lv test/ +- cover + +after_success: +- cover -report coveralls + +notifications: + irc: + channels: + - irc.freenode.net#ingy + on_success: change + on_failure: always + skip_join: true + +# Hack to not run on tag pushes: +branches: + except: + - /^v?[0-9]+\.[0-9]+/ diff --git a/Changes b/Changes index ce787df..dad057c 100644 --- a/Changes +++ b/Changes @@ -1,30 +1,30 @@ --- +version: 0.16 +date: Sat Jul 26 00:19:48 PDT 2014 +changes: +- Switch to Zilla::Dist +--- version: 0.15 date: Sat Apr 18 09:21:21 PDT 2009 -change: +changes: - Make stack trace not say ANON - --- version: 0.14 date: Fri Apr 25 12:20:38 CST 2008 -change: +changes: - Make Class::Field work with utf8 package names - --- version: 0.12 date: Fri Feb 17 11:48:15 PST 2006 -change: +changes: - 0.11 got corrupted on the way to CPAN. Grrrrrrrrrr! - --- version: 0.11 date: Fri Feb 17 11:32:47 PST 2006 -change: +changes: - 0.10 got corrupted on the way to CPAN - --- version: 0.10 date: Tue Jan 31 00:44:04 PST 2006 -change: +changes: - Maiden voyage - diff --git a/Contributing b/Contributing new file mode 100644 index 0000000..121255d --- /dev/null +++ b/Contributing @@ -0,0 +1,55 @@ +Contributing +============ + +The "Class-Field" Project needs your help! + +Please consider being a contributor. This file contains instructions that will +help you be an effective contributor to the Project. + +GitHub +------ + +The code for this Project is hosted at GitHub. The repository is: + + https://github.com/ingydotnet/class-field-pm + +You can get the code with this command: + + git clone https://github.com/ingydotnet/class-field-pm + +If you've found a bug or a missing feature that you would like the author to +know about, report it here: + + https://github.com/ingydotnet/class-field-pm/issues + +or fix it and submit a pull request here: + + https://github.com/ingydotnet/class-field-pm/pulls + +See these links for help on interacting with GitHub: + +* https://help.github.com/ +* https://help.github.com/articles/creating-a-pull-request + +Zilla::Dist +----------- + +This Project uses Zilla::Dist to prepare it for publishing to CPAN. Read: + + https://metacpan.org/pod/distribution/Zilla-Dist/lib/Zilla/Dist/Contributing.pod + +for up-to-date instructions on what contributors like yourself need to know to +use it. + +IRC +--- + +Class-Field has an IRC channel where you can find real people to help you: + + irc.freenode.net#ingy + +Join the channel. Join the team! + + + Thanks in advance, Ingy döt Net + diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP deleted file mode 100644 index 8e837df..0000000 --- a/MANIFEST.SKIP +++ /dev/null @@ -1,14 +0,0 @@ -^MANIFEST\.SKIP$ -^.git/ -^.gitignore -^Makefile$ -^pm_to_blib$ -^blib -^\.vimrc$ -^pyyaml -^init.py$ -^Notes$ -^ToDo$ -^BPW-Talk -^Review -^Hacks/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..01b4e72 --- /dev/null +++ b/Makefile @@ -0,0 +1,181 @@ +# DO NOT EDIT. +# +# This Makefile came from Zilla::Dist. To upgrade it, run: +# +# > make upgrade +# + +.PHONY: cpan test + +PERL ?= $(shell which perl) +ZILD := $(PERL) -S zild + +ifneq (,$(shell which zild)) + NAMEPATH := $(shell $(ZILD) meta =cpan/libname) +ifeq (,$(NAMEPATH)) + NAMEPATH := $(shell $(ZILD) meta name) +endif + NAME := $(shell $(ZILD) meta name) + VERSION := $(shell $(ZILD) meta version) + RELEASE_BRANCH := $(shell $(ZILD) meta branch) +else + NAME := No-Name + NAMEPATH := $(NAME) + VERSION := 0 + RELEASE_BRANCH := master +endif + +DISTDIR := $(NAME)-$(VERSION) +DIST := $(DISTDIR).tar.gz +NAMEPATH := $(subst -,/,$(NAMEPATH)) +SUCCESS := "$(DIST) Released!!!" + +default: help + +help: + @echo '' + @echo 'Makefile targets:' + @echo '' + @echo ' make test - Run the repo tests' + @echo ' make install - Install the dist from this repo' + @echo ' make prereqs - Install the CPAN prereqs' + @echo ' make update - Update generated files' + @echo ' make release - Release the dist to CPAN' + @echo '' + @echo ' make cpan - Make cpan/ dir with dist.ini' + @echo ' make cpanshell - Open new shell into new cpan/' + @echo ' make cpantest - Make cpan/ dir and run tests in it' + @echo '' + @echo ' make dist - Make CPAN distribution tarball' + @echo ' make distdir - Make CPAN distribution directory' + @echo ' make distshell - Open new shell into new distdir' + @echo ' make disttest - Run the dist tests' + @echo '' + @echo ' make upgrade - Upgrade the build system (Makefile)' + @echo ' make readme - Make the ReadMe.pod file' + @echo ' make travis - Make a travis.yml file' + @echo '' + @echo ' make clean - Clean up build files' + @echo ' make help - Show this help' + @echo '' + +test: +ifeq ($(wildcard pkg/no-test),) + $(PERL) -S prove -lv test +else + @echo "Testing not available. Use 'disttest' instead." +endif + +install: distdir + @echo '***** Installing $(DISTDIR)' + (cd $(DISTDIR); perl Makefile.PL; make install) + make clean + +prereqs: + cpanm `$(ZILD) meta requires` + +update: makefile + @echo '***** Updating/regenerating repo content' + make readme contrib travis version + +release: clean update check-release date test disttest + @echo '***** Releasing $(DISTDIR)' + make dist + cpan-upload $(DIST) + make clean + [ -z "$$(git status -s)" ] || git commit -am '$(VERSION)' + git push + git tag $(VERSION) + git push --tag + make clean + git status + @echo + @[ -n "$$(which cowsay)" ] && cowsay "$(SUCCESS)" || echo "$(SUCCESS)" + @echo + +cpan: + @echo '***** Creating the `cpan/` directory' + zild-make-cpan + +cpanshell: cpan + @echo '***** Starting new shell in `cpan/` directory' + (cd cpan; $$SHELL) + make clean + +cpantest: cpan +ifeq ($(wildcard pkg/no-test),) + @echo '***** Running tests in `cpan/` directory' + (cd cpan; $(PERL) -S prove -lv t) && make clean +else + @echo "Testing not available. Use 'disttest' instead." +endif + +dist: clean cpan + @echo '***** Creating new dist: $(DIST)' + (cd cpan; dzil build) + mv cpan/$(DIST) . + rm -fr cpan + +distdir: clean cpan + @echo '***** Creating new dist directory: $(DISTDIR)' + (cd cpan; dzil build) + mv cpan/$(DIST) . + tar xzf $(DIST) + rm -fr cpan $(DIST) + +distshell: distdir + @echo '***** Starting new shell in `$(DISTDIR)` directory' + (cd $(DISTDIR); $$SHELL) + make clean + +disttest: cpan + @echo '***** Running tests in `$(DISTDIR)` directory' + (cd cpan; dzil test) && make clean + +upgrade: + @echo '***** Checking that Zilla-Dist Makefile is up to date' + cp `$(ZILD) sharedir`/Makefile ./ + +readme: + swim --pod-cpan doc/$(NAMEPATH).swim > ReadMe.pod + +contrib: + $(PERL) -S zild-render-template Contributing + +travis: + $(PERL) -S zild-render-template travis.yml .travis.yml + +clean purge: + rm -fr cpan .build $(DIST) $(DISTDIR) + +#------------------------------------------------------------------------------ +# Non-pulic-facing targets: +#------------------------------------------------------------------------------ +check-release: + @echo '***** Checking readiness to release $(DIST)' + RELEASE_BRANCH=$(RELEASE_BRANCH) zild-check-release + git stash + git pull --rebase origin $(RELEASE_BRANCH) + git stash pop + +# We don't want to update the Makefile in Zilla::Dist since it is the real +# source, and would be reverting to whatever was installed. +ifeq (Zilla-Dist,$(NAME)) +makefile: + @echo Skip 'make upgrade' +else +makefile: + @cp Makefile /tmp/ + make upgrade + @if [ -n "`diff Makefile /tmp/Makefile`" ]; then \ + echo "ATTENTION: Dist-Zilla Makefile updated. Please re-run the command."; \ + exit 1; \ + fi + @rm /tmp/Makefile +endif + +date: + $(ZILD) changes date "`date`" + +version: + $(PERL) -S zild-version-update diff --git a/Makefile.PL b/Makefile.PL deleted file mode 100644 index 33315db..0000000 --- a/Makefile.PL +++ /dev/null @@ -1,8 +0,0 @@ -use inc::Module::Install; - -name 'Class-Field'; -all_from 'lib/Class/Field.pm'; - -use_test_base; - -WriteAll; diff --git a/Meta b/Meta new file mode 100644 index 0000000..d9eab5e --- /dev/null +++ b/Meta @@ -0,0 +1,28 @@ +=meta: 0.0.1 + +name: Class-Field +version: 0.16 +abstract: Class Field Accessor Generator +homepage: https://metacpan.org/release/Class-Field + +license: perl +copyright: 2001-2014. Ingy döt Net. +author: + name: Ingy döt Net + email: ingy@cpan.org + github: ingydotnet + twitter: ingydotnet + freenode: ingy + homepage: http://ingy.net + +requires: + perl: 5.8.1 + +devel: + git: https://github.com/ingydotnet/class-field-pm + bug: https://github.com/ingydotnet/class-field-pm/issues + irc: irc.freenode.net#ingy + +=travis: + type: perl + irc: irc.freenode.net#ingy diff --git a/README b/README deleted file mode 100644 index e199412..0000000 --- a/README +++ /dev/null @@ -1,68 +0,0 @@ -NAME - Class::Field - Class Field Accessor Generator - -SYNOPSIS - package Thing; - use Class::Field qw'field const'; - - field 'this'; - field 'list' => []; - field 'map' => {}; - field 'that', -init => '$self->setup_that'; - field 'circular_ref' => -weaken; - const 'answer' => 42; - -DESCRIPTION - Class::Field exports two subroutines, "field" and "const". These - functions are used to declare fields and constants in your class. - - Class::Field generates custom code for each accessor that is optimized - for speed. - -FUNCTIONS - * field - - Defines accessor methods for a field of your class: - - package Example; - use base 'Parent'; - use Class::Field qw'field const'; - - field 'foo'; - field bar => []; - - sub lalala { - my $self = shift; - $self->foo(42); - push @{$self->{bar}}, $self->foo; - } - - The first parameter passed to "field" is the name of the attribute - being defined. Accessors can be given an optional default value. - This value will be returned if no value for the field has been set - in the object. - - * const - - const bar => 42; - - The "const" function is similar to except that it is - immutable. It also does not store data in the object. You probably - always want to give a "const" a default value, otherwise the - generated method will be somewhat useless. - -NOTE - This code was taken directly out the Spiffy module for those people who - just want this functionality without using the rest of Spiffy. - -AUTHOR - Ingy döt Net - -COPYRIGHT - Copyright (c) 2006, 2008. Ingy döt Net. - - This program is free software; you can redistribute it and/or modify it - under the same terms as Perl itself. - - See - diff --git a/ReadMe.pod b/ReadMe.pod new file mode 100644 index 0000000..c7fbfb1 --- /dev/null +++ b/ReadMe.pod @@ -0,0 +1,91 @@ +=pod + +=for comment +DO NOT EDIT. This Pod was generated by Swim. +See http://github.com/ingydotnet/swim-pm#readme + +=encoding utf8 + +=head1 NAME + +Class::Field - Class Field Accessor Generator + +=for html +class-field-pm +class-field-pm + +=head1 SYNOPSIS + + package Thing; + use Class::Field qw'field const'; + + field 'this'; + field 'list' => []; + field 'map' => {}; + field 'that', -init => '$self->setup_that'; + field 'circular_ref' => -weaken; + const 'answer' => 42; + +=head1 DESCRIPTION + +Class::Field exports two subroutines, C and C. These functions +are used to declare fields and constants in your class. + +Class::Field generates custom code for each accessor that is optimized +for speed. + +=head1 FUNCTIONS + +=over + +=item C + +Defines accessor methods for a field of your class: + + package Example; + use base 'Parent'; + use Class::Field qw'field const'; + + field 'foo'; + field bar => []; + + sub lalala { + my $self = shift; + $self->foo(42); + push @{$self->{bar}}, $self->foo; + } + +The first parameter passed to C is the name of the attribute being +defined. Accessors can be given an optional default value. This value will be +returned if no value for the field has been set in the object. + +=item C + + const bar => 42; + +The C function is similar to except that it is immutable. +It also does not store data in the object. You probably always want to +give a C a default value, otherwise the generated method will be +somewhat useless. + +=back + +=head1 NOTE + +this code was taken directly out the Spiffy module for those people who just +want this functionality without using the rest of Spiffy. + +=head1 AUTHOR + +ingy döt Net + +=head1 COPYRIGHT + +Copyright 2006-2014. Ingy döt Net. + +This program is free software; you can redistribute it and/or modify it under +the same terms as Perl itself. + +See L + +=cut diff --git a/doc/Class/Field.swim b/doc/Class/Field.swim new file mode 100644 index 0000000..30debb8 --- /dev/null +++ b/doc/Class/Field.swim @@ -0,0 +1,76 @@ +Class::Field +============ + +Class Field Accessor Generator + + + += Synopsis + + package Thing; + use Class::Field qw'field const'; + + field 'this'; + field 'list' => []; + field 'map' => {}; + field 'that', -init => '$self->setup_that'; + field 'circular_ref' => -weaken; + const 'answer' => 42; + += Description + +Class::Field exports two subroutines, `field` and `const`. These +functions are used to declare fields and constants in your class. + +Class::Field generates custom code for each accessor that is optimized +for speed. + += Functions + +- `field` + + Defines accessor methods for a field of your class: + + package Example; + use base 'Parent'; + use Class::Field qw'field const'; + + field 'foo'; + field bar => []; + + sub lalala { + my $self = shift; + $self->foo(42); + push @{$self->{bar}}, $self->foo; + } + + The first parameter passed to `field` is the name of the attribute being + defined. Accessors can be given an optional default value. This value will + be returned if no value for the field has been set in the object. + +- `const` + + const bar => 42; + + The `const` function is similar to except that it is immutable. It + also does not store data in the object. You probably always want to give a + `const` a default value, otherwise the generated method will be somewhat + useless. + += Note + +this code was taken directly out the Spiffy module for those people who just +want this functionality without using the rest of Spiffy. + += Author + +ingy döt Net + += Copyright + +Copyright 2006-2014. Ingy döt Net. + +This program is free software; you can redistribute it and/or modify it under +the same terms as Perl itself. + +See http://www.perl.com/perl/misc/Artistic.html diff --git a/lib/Class/Field.pm b/lib/Class/Field.pm index 4f5663e..6a353b3 100644 --- a/lib/Class/Field.pm +++ b/lib/Class/Field.pm @@ -1,13 +1,13 @@ +use strict; use warnings; package Class::Field; -use 5.006001; -use strict; -use warnings; +our $VERSION = '0.16'; + use base 'Exporter'; -use Encode; -our $VERSION = '0.15'; our @EXPORT_OK = qw(field const); +use Encode; + my %code = ( sub_start => "sub {\n local \*__ANON__ = \"%s::%s\";\n", @@ -62,7 +62,7 @@ sub field { if defined $default; $code .= sprintf $code{return_if_get}, $field; $code .= sprintf $code{set}, $field; - $code .= sprintf $code{weaken}, $field, $field + $code .= sprintf $code{weaken}, $field, $field if $args->{-weak}; $code .= sprintf $code{sub_end}, $field; @@ -119,91 +119,10 @@ sub parse_arguments { push @values, $elem; } } - return wantarray ? ($args, @values) : $args; + return wantarray ? ($args, @values) : $args; } sub boolean_arguments { () } sub paired_arguments { () } -__END__ - -=head1 NAME - -Class::Field - Class Field Accessor Generator - -=head1 SYNOPSIS - - package Thing; - use Class::Field qw'field const'; - - field 'this'; - field 'list' => []; - field 'map' => {}; - field 'that', -init => '$self->setup_that'; - field 'circular_ref' => -weaken; - const 'answer' => 42; - -=head1 DESCRIPTION - -Class::Field exports two subroutines, C and C. These -functions are used to declare fields and constants in your class. - -Class::Field generates custom code for each accessor that is optimized -for speed. - -=head1 FUNCTIONS - -=over 4 - -=item * field - -Defines accessor methods for a field of your class: - - package Example; - use base 'Parent'; - use Class::Field qw'field const'; - - field 'foo'; - field bar => []; - - sub lalala { - my $self = shift; - $self->foo(42); - push @{$self->{bar}}, $self->foo; - } - -The first parameter passed to C is the name of the attribute -being defined. Accessors can be given an optional default value. -This value will be returned if no value for the field has been set -in the object. - -=item * const - - const bar => 42; - -The C function is similar to except that it is immutable. -It also does not store data in the object. You probably always want to -give a C a default value, otherwise the generated method will be -somewhat useless. - -=back - -=head1 NOTE - -This code was taken directly out the Spiffy module for those people who just -want this functionality without using the rest of Spiffy. - -=head1 AUTHOR - -Ingy döt Net - -=head1 COPYRIGHT - -Copyright (c) 2006, 2008, 2009. Ingy döt Net. - -This program is free software; you can redistribute it and/or modify it -under the same terms as Perl itself. - -See L - -=cut +1; diff --git a/t/Base.pm b/test/TestFieldBase.pm similarity index 86% rename from t/Base.pm rename to test/TestFieldBase.pm index d1e28d5..fe1c40a 100644 --- a/t/Base.pm +++ b/test/TestFieldBase.pm @@ -1,4 +1,4 @@ -package t::Base; +package TestFieldBase; sub new { my $self = bless {}, shift; diff --git a/t/anon.t b/test/anon.t similarity index 100% rename from t/anon.t rename to test/anon.t diff --git a/t/const.t b/test/const.t similarity index 80% rename from t/const.t rename to test/const.t index c5ca7f0..a5c9e08 100644 --- a/t/const.t +++ b/test/const.t @@ -1,7 +1,11 @@ +use strict; +use File::Basename; +use lib dirname(__FILE__), 'inc'; + use Test::More tests => 4; package Foo; -use base 't::Base'; +use base 'TestFieldBase'; use Class::Field 'const'; const 'this' => 'Charming Man'; diff --git a/t/field.t b/test/field.t similarity index 90% rename from t/field.t rename to test/field.t index 5cd9a39..2d4b17b 100644 --- a/t/field.t +++ b/test/field.t @@ -1,7 +1,11 @@ +use strict; +use File::Basename; +use lib dirname(__FILE__), 'inc'; + use Test::More tests => 9; package Foo; -use base 't::Base'; +use base 'TestFieldBase'; use Class::Field 'field'; field 'x';