Codebase list libmoosex-has-sugar-perl / 5af009b
[svn-upgrade] Integrating new upstream version, libmoosex-has-sugar-perl (0.0404) Jonathan Yu 14 years ago
26 changed file(s) with 503 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
1212 "Kent\ Fredric\ \<kentnl\ at\ cpan\.org\>",
1313 ],
1414 requires => {
15 "MooseX::Types::Moose" => '0',
1516 "namespace::autoclean" => '0',
1617 "Test::Exception" => '0',
1718 "Sub::Exporter" => '0',
00 Revision history for MooseX-Has-Sugar
1
2 0.0404 2009-07-06 03:34:10 UTC
3 Added Saccharin, experimental sugars.
14
25 0.0403 2009-06-30 13:56:07 UTC
36 Using Dist::Zilla's handy author-tests feature
77 README
88 lib/MooseX/Has/Sugar.pm
99 lib/MooseX/Has/Sugar/Minimal.pm
10 lib/MooseX/Has/Sugar/Saccharin.pm
1011 t/00-load.t
1112 t/04_values.t
1213 t/04_values/AMinimal.pm
2122 t/06_attr_required/TestPackage.pm
2223 t/07_attr_lazy_build.t
2324 t/07_attr_lazy_build/TestPackage.pm
25 t/08_saccharin.t
26 t/08_saccharin/TestPackage.pm
27 t/09_saccharin.t
28 t/09_saccharin/TestPackage.pm
29 t/author-01.whitespace.t
2430 t/author-boilerplate.t
25 t/author-pod.t
31 t/author-pod.t
32 t/lib/TestClean.pm
66 "url" : "http://module-build.sourceforge.net/META-spec-v1.4.html"
77 },
88 "generated_by" : "Dist::Zilla::Plugin::MetaJSON version 1.091610",
9 "version" : "0.0403",
9 "version" : "0.0404",
1010 "name" : "MooseX-Has-Sugar",
1111 "author" : [
1212 "Kent Fredric <kentnl at cpan.org>"
1313 ],
1414 "license" : "perl",
1515 "requires" : {
16 "MooseX::Types::Moose" : "0",
1617 "namespace::autoclean" : "0",
1718 "Test::Exception" : "0",
1819 "Sub::Exporter" : "0",
1111 Carp: 0
1212 Find::Lib: 0
1313 Moose: 0.84
14 MooseX::Types::Moose: 0
1415 Sub::Exporter: 0
1516 Test::Exception: 0
1617 Test::More: 0
1819 namespace::autoclean: 0
1920 resources:
2021 repository: git://github.com/kentfredric/MooseX-Has-Sugar.git
21 version: 0.0403
22 version: 0.0404
88 NAME => 'MooseX::Has::Sugar',
99 AUTHOR => 'Kent\ Fredric\ \<kentnl\ at\ cpan\.org\>',
1010 ABSTRACT => 'Sugar\ Syntax\ for\ moose\ \'has\'\ fields',
11 VERSION => '0.0403',
11 VERSION => '0.0404',
1212 EXE_FILES => [ qw() ],
1313 (eval { ExtUtils::MakeMaker->VERSION(6.21) } ? (LICENSE => 'perl') : ()),
1414 PREREQ_PM => {
15 "MooseX::Types::Moose" => '0',
1516 "namespace::autoclean" => '0',
1617 "Test::Exception" => '0',
1718 "Sub::Exporter" => '0',
11 MooseX::Has::Sugar - Sugar Syntax for moose 'has' fields
22
33 VERSION
4 version 0.0403
4 version 0.0404
55
66 SYNOPSIS
77 Moose "has" syntax is generally fine, but sometimes one gets bothered
00 package MooseX::Has::Sugar::Minimal;
1 our $VERSION = '0.0403';
1 our $VERSION = '0.0404';
22
33
44 # ABSTRACT: Less Sugary Syntax for moose 'has' fields
4343
4444 =head1 VERSION
4545
46 version 0.0403
46 version 0.0404
4747
4848 =head1 SYNOPSIS
4949
7474
7575 =item bare
7676
77 =back
77 =back
7878
7979 =head1 EXPORT GROUPS
8080
8888
8989 Exports C<ro> and C<rw> and C<bare>
9090
91 =back
91 =back
9292
9393 =head1 CONFLICTS
9494
130130
131131 returns C<('bare')>
132132
133 =back
133 =back
134134
135135 =head1 BUGS
136136
168168
169169 L<http://search.cpan.org/dist/MooseX-Has-Sugar/>
170170
171 =back
171 =back
172172
173173 =head1 ACKNOWLEDGEMENTS
174
175
176174
177175 =head1 AUTHOR
178176
185183 This is free software; you can redistribute it and/or modify it under
186184 the same terms as the Perl 5 programming language system itself.
187185
188 =cut
186 =cut
189187
190188
191189
0 package MooseX::Has::Sugar::Saccharin;
1 our $VERSION = '0.0404';
2
3
4 # ABSTRACT: Experimental sweetness
5
6 use warnings;
7 use strict;
8
9
10 use Carp ();
11 use Sub::Exporter ();
12
13 Sub::Exporter::setup_exporter(
14 {
15 exports => [
16 'ro', 'rw', 'required', 'lazy', 'lazy_build', 'coerce', 'weak_ref', 'auto_deref',
17 'bare', 'default', 'init_arg', 'predicate', 'clearer', 'builder', 'trigger',
18 ],
19 groups => { default => ['-all'], }
20 }
21 );
22
23
24 sub bare($) {
25 return ( 'is', 'bare', 'isa', shift, );
26 }
27
28
29 sub ro($) {
30 return ( 'is', 'ro', 'isa', shift, );
31 }
32
33
34 sub rw($) {
35 return ( 'is', 'rw', 'isa', shift, );
36 }
37
38
39 sub required(@) {
40 return ( 'required', 1, @_ );
41 }
42
43
44 sub lazy(@) {
45 return ( 'lazy', 1, @_ );
46 }
47
48
49 sub lazy_build(@) {
50 return ( 'lazy_build', 1, @_ );
51 }
52
53
54 sub weak_ref(@) {
55 return ( 'weak_ref', 1, @_ );
56 }
57
58
59 sub coerce(@) {
60 return ( 'coerce', 1, @_ );
61 }
62
63
64 sub auto_deref(@) {
65 return ( 'auto_deref', 1, @_ );
66 }
67
68
69 sub builder($) {
70 return ( 'builder', shift );
71 }
72
73
74 sub predicate($) {
75 return ( 'predicate', shift );
76 }
77
78
79 sub clearer($) {
80 return ( 'clearer', shift );
81 }
82
83
84 sub init_arg($) {
85 return ( 'init_arg', shift );
86 }
87
88
89 sub default(&) {
90 my $code = shift;
91 return (
92 'default',
93 sub {
94 my $self = $_[0];
95 local $_ = $self;
96 return $code->();
97 }
98 );
99 }
100
101
102 sub trigger(&) {
103 my $code = shift;
104 return (
105 'trigger',
106 sub {
107 my $self = $_[0];
108 local $_ = $self;
109 return $code->();
110 }
111 );
112 }
113 1;
114
115
116 __END__
117
118 =pod
119
120 =head1 NAME
121
122 MooseX::Has::Sugar::Saccharin - Experimental sweetness
123
124 =head1 VERSION
125
126 version 0.0404
127
128 =head1 SYNOPSIS
129
130 This is a highly experimental sugaring module. No Guarantees of stability.
131
132 has name => rw Str, default { 1 };
133 has suffix => required rw Str;
134 has 'suffix', required rw Str;
135
136 Your choice.
137
138 =head1 FUNCTIONS
139
140 =head2 bare $Type
141
142 bare Str
143
144 equivalent to this
145
146 is => 'bare', isa => Str
147
148 =head2 ro $Type
149
150 ro Str
151
152 equivalent to this
153
154 is => 'ro', isa => Str,
155
156 =head2 rw $Type
157
158 rw Str
159
160 equivalent to this
161
162 is => 'rw', isa => Str
163
164 =head2 required @rest
165
166 this
167
168 required rw Str
169
170 is equivalent to this
171
172 required => 1, is => 'rw', isa => Str,
173
174 this
175
176 rw Str, required
177
178 is equivalent to this
179
180 is => 'rw', isa => Str , required => 1
181
182 =head2 lazy @rest
183
184 like C<( lazy => 1 , @rest )>
185
186 =head2 lazy_build @rest
187
188 like C<( lazy_build => 1, @rest )>
189
190 =head2 weak_ref @rest
191
192 like C<( weak_ref => 1, @rest )>
193
194 =head2 coerce @rest
195
196 like C<( coerce => 1, @rest )>
197
198 =head2 auto_deref @rest
199
200 like C<( auto_deref => 1, @rest )>
201
202 =head2 builder $buildername
203
204 ie:
205
206 required rw Str, builder '_build_foo'
207
208 is like
209
210 builder => '_build_foo'
211
212 =head2 predicate $predicatename
213
214 see builder
215
216 =head2 clearer $clearername
217
218 see builder
219
220 =head2 init_arg $argname
221
222 see builder
223
224 =head2 default { $code }
225
226 Examples:
227
228 default { 1 }
229 default { { } }
230 default { [ ] }
231 default { $_->otherfield }
232
233 $_ is localised as the same value as $_[0] for convenience ( usually $self )
234
235 =head2 trigger { $code }
236
237 Works exactly like default.
238
239 =head1 ACKNOWLEDGEMENTS
240
241 =head1 AUTHOR
242
243 Kent Fredric <kentnl at cpan.org>
244
245 =head1 COPYRIGHT AND LICENSE
246
247 This software is copyright (c) 2009 by Kent Fredric.
248
249 This is free software; you can redistribute it and/or modify it under
250 the same terms as the Perl 5 programming language system itself.
251
252 =cut
253
254
00 package MooseX::Has::Sugar;
1 our $VERSION = '0.0403';
1 our $VERSION = '0.0404';
22
33
44 # ABSTRACT: Sugar Syntax for moose 'has' fields
7979
8080 =head1 VERSION
8181
82 version 0.0403
82 version 0.0404
8383
8484 =head1 SYNOPSIS
8585
215215
216216 =item auto_deref
217217
218 =back
218 =back
219219
220220 =head1 EXPORT GROUPS
221221
258258
259259 This is a shorthand for qw( :isattrs :attrs )
260260
261 =back
261 =back
262262
263263 =head1 FUNCTIONS
264264
303303
304304 returns C<('auto_deref',1)>
305305
306 =back
306 =back
307307
308308 =head1 BUGS
309309
340340
341341 L<http://search.cpan.org/dist/MooseX-Has-Sugar/>
342342
343 =back
343 =back
344344
345345 =head1 ACKNOWLEDGEMENTS
346
347
348346
349347 =head1 AUTHOR
350348
357355 This is free software; you can redistribute it and/or modify it under
358356 the same terms as the Perl 5 programming language system itself.
359357
360 =cut
361
362
358 =cut
359
360
00 package AMinimal;
1 our $VERSION = '0.0403';
1 our $VERSION = '0.0404';
22
33
44 # $Id:$
00 package BDeclare;
1 our $VERSION = '0.0403';
1 our $VERSION = '0.0404';
22
33
44 # $Id:$
00 package CDeclareRo;
1 our $VERSION = '0.0403';
1 our $VERSION = '0.0404';
22
33
44 # $Id:$
00 package DEverything;
1 our $VERSION = '0.0403';
1 our $VERSION = '0.0404';
22
33
44 # $Id:$
00 package EMixed;
1 our $VERSION = '0.0403';
1 our $VERSION = '0.0404';
22
33
44 # $Id:$
00 package TestCant;
1 our $VERSION = '0.0403';
1 our $VERSION = '0.0404';
22
33
44 # $Id:$
00 package TestPackage;
1 our $VERSION = '0.0403';
1 our $VERSION = '0.0404';
22
33
44 # $Id:$
00 package TestPackage;
1 our $VERSION = '0.0403';
1 our $VERSION = '0.0404';
22
33
44 # $Id:$
00 package TestPackage;
1 our $VERSION = '0.0403';
1 our $VERSION = '0.0404';
22
33
44 # $Id:$
0 package TestPackage;
1 our $VERSION = '0.0404';
2
3
4 # $Id:$
5 use strict;
6 use warnings;
7 use Moose;
8 use namespace::autoclean;
9
10 use MooseX::Has::Sugar::Saccharin;
11 use MooseX::Types::Moose (':all');
12
13 has roattr => lazy_build ro Str;
14
15 has rwattr => lazy_build rw Str;
16
17 sub _build_rwattr {
18 return 'y';
19 }
20
21 sub _build_roattr {
22 return 'y';
23 }
24
25 __PACKAGE__->meta->make_immutable;
26
27 1;
28
0
1 use strict;
2 use warnings;
3
4 use Test::More tests => 7; # last test to print
5 use Test::Exception;
6 use Find::Lib './08_saccharin';
7
8 use TestPackage;
9
10 sub cr {
11 return TestPackage->new();
12 }
13
14 pass("Syntax Compiles");
15
16 lives_ok( sub { cr() }, 'Construction still works' );
17
18 my $i = cr();
19
20 is( $i->roattr, 'y', 'Builders Still Trigger 1' );
21 is( $i->rwattr, 'y', 'Builders Still Trigger 2' );
22
23 dies_ok( sub { $i->roattr('x') }, "RO works still" );
24
25 lives_ok( sub { $i->rwattr('x') }, 'RW works still' );
26
27 is( $i->rwattr(), 'x', "RW Works as expected" );
28
0 package TestPackage;
1 our $VERSION = '0.0404';
2
3
4 # $Id:$
5 use strict;
6 use warnings;
7 use Moose;
8 use MooseX::Types::Moose (':all');
9 use MooseX::Has::Sugar::Saccharin;
10 use namespace::autoclean;
11
12 sub Alpha {
13 return {
14 orig => { 'isa' => Str, 'required' => 1, 'is' => 'rw' },
15 mx => { required rw Str },
16 };
17 }
18
19 sub Beta {
20 return {
21 orig => { 'isa' => Str, 'required' => 1, 'is' => 'rw' },
22 mx => { rw Str, required },
23 };
24 }
25
26 sub Gamma {
27 return {
28 orig => {
29 'isa' => Str,
30 'is' => 'rw',
31 default => sub {
32 return 1;
33 }
34 },
35 mx => { rw Str, default { 1 } },
36 };
37 }
38
39 1;
40
0 use strict;
1 use warnings;
2
3 use Test::More tests => 3; # last test to print
4 use Find::Lib './09_saccharin';
5 use TestPackage;
6
7 is_deeply( TestPackage->Alpha->{orig}, TestPackage->Alpha->{mx}, 'Basic Use Case', );
8 is_deeply( TestPackage->Beta->{orig}, TestPackage->Beta->{mx}, 'Order Invert', );
9 is_deeply( TestPackage->Gamma->{orig}->{default}->(), TestPackage->Gamma->{mx}->{default}->(), 'Subs', );
10
0
1 BEGIN {
2 unless ($ENV{AUTHOR_TESTING}) {
3 require Test::More;
4 Test::More::plan(skip_all => 'these tests are for testing by the author');
5 }
6 }
7
8 #
9 # This test checks all files in the dist of interest for excess whitespace,
10 # or bad whitespace
11 #
12
13 use strict;
14 use warnings;
15
16 use File::Find::Rule;
17 use File::Find::Rule::Perl;
18 use Path::Class qw( file dir );
19 use FindBin;
20 use Moose::Autobox;
21
22 use Test::More qw( no_plan );
23 use lib "$FindBin::Bin/lib";
24 use TestClean;
25
26 my ($dir) = ( dir($FindBin::Bin)->parent );
27 my (@subdirs) = ( map { $dir->subdir($_) } qw( lib t ) );
28 my (@files);
29 push @files, File::Find::Rule->perl_file->in(@subdirs);
30 push @files, File::Find::Rule->name("*.ini")->in("$dir");
31
32 for (@files) {
33 my $fn = file($_)->relative($dir)->stringify;
34 is_clean($fn);
35 }
1212 use Test::More;
1313
1414 # Ensure a recent version of Test::Pod
15 my $min_tp = 1.22;
16 eval "use Test::Pod $min_tp";
17 plan skip_all => "Test::Pod $min_tp required for testing POD" if $@;
15 use Test::Pod 1.22;
1816
1917 all_pod_files_ok();
0 package TestClean;
1 our $VERSION = '0.0404';
2
3
4 # $Id:$
5 my $CLASS = __PACKAGE__;
6 use base 'Test::Builder::Module';
7 @EXPORT = qw( is_clean );
8
9 sub pp {
10 require Data::Dumper;
11 local $Data::Dumper::Terse = 1;
12 local $Data::Dumper::Useqq = 1;
13 local $Data::Dumper::Indent = 0;
14 return Data::Dumper::Dumper(shift);
15 }
16
17 sub is_clean($;$) {
18 my $file = shift;
19 my $msg = shift;
20 $msg ||= "Cleanlyness for $file";
21 my $tb = $CLASS->builder;
22 my $fh;
23 my $o;
24 if ( not open $fh, '<', $file ) {
25 my $o = $tb->ok( 0, $msg );
26 $tb->diag("Loading $file Failed");
27 return $o;
28 }
29 while ( my $line = <$fh> ) {
30
31 # Tailing Whitespace is pesky
32 if ( $line =~ qr/\h$/m ) {
33 $o = $tb->ok( 0, $msg ) unless $o;
34 $tb->diag( "\n\n\\h found on end of line $. in $file\n" . pp($line) . "\n" );
35 }
36
37 # Tabs are teh satan.
38 if ( $line =~ qr/\t/m ) {
39 $o = $tb->ok( 0, $msg ) unless $o;
40 $tb->diag( "\\t found in line $. in $file\n" . pp($line) . "\n" );
41 }
42
43 # Perltidyness in teh comments
44 if ( $line =~ qr/[)][{]/ ) {
45 $o = $tb->ok( 0, $msg ) unless $o;
46 $tb->diag( ')' . "{ found in line $. in $file\n" . pp($line) . "\n" );
47 }
48 }
49 close $fh;
50 if ($o) {
51 return $o;
52 }
53 return $tb->ok( 1, $msg );
54 }
55
56 1;