Codebase list libautobox-core-perl / d7c639b
removed trailing whitespace from source files, it makes my life a little bit easier Tomasz Konojacki 8 years ago
2 changed file(s) with 24 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
44 # o. Lars D implemented a times() method for scalars but there is no doc or comment and I don't see the point; commented it out for now.
55 # (scrottie)
66 # o. @array->random ?
7 # o. "5->times(sub { print "hi\n"}); # XXX likely to change but it's in the code so bloody doc it so I have incentive to rethink it".
7 # o. "5->times(sub { print "hi\n"}); # XXX likely to change but it's in the code so bloody doc it so I have incentive to rethink it".
88 # well? do we want this? (scrottie)
99 # o. kill head() and tail() -- does it really make sense to try to emulate linked lists with Perl arrays? cute idea, but, uh. (scrottie)
1010 # o. "There's currently no counterpart to the C<< \ >> operator" -- but should we back away from trying to name operators and
8686 [10, 20, 30, 40, 50]->pop->say;
8787 [10, 20, 30, 40, 50]->shift->say;
8888
89 my $lala = "Lalalalala\n";
89 my $lala = "Lalalalala\n";
9090 "chomp: "->concat($lala->chomp, " ", $lala)->say;
9191
9292 my $hashref = { foo => 10, bar => 20, baz => 30, qux => 40 };
132132 messy dereferencing syntaxes.
133133
134134 F<autobox::Core> is mostly glue. It presents existing functions with a new
135 interface, while adding few extra. Most of the methods read like
135 interface, while adding few extra. Most of the methods read like
136136 C<< sub hex { CORE::hex($_[0]) } >>. In addition to built-ins from
137137 L<perlfunc> that operate on hashes, arrays, scalars, and code references,
138138 some Perl 6-ish things have been included, and some keywords like
204204 context), L<rindex|perlfunc/rindex>,
205205 L<sprintf|perlfunc/sprintf>, L<substr|perlfunc/substr>, L<uc|perlfunc/uc>
206206 L<ucfirst|perlfunc/ucfirst>, L<unpack|perlfunc/unpack>, L<quotemeta|perlfunc/quotemeta>,
207 L<vec|perlfunc/vec>, L<undef|perlfunc/undef>,
207 L<vec|perlfunc/vec>, L<undef|perlfunc/undef>,
208208 L<split|perlfunc/split>, L<system|perlfunc/system>, L<eval|perlfunc/eval>.
209209
210210 In addition, so are each of the following:
213213
214214 $string1->concat($string2);
215215
216 Concatenates C<$string2> to C<$string1>. This
216 Concatenates C<$string2> to C<$string1>. This
217217 corresponds to the C<.> operator used to join two strings. Returns the
218218 joined strings.
219219
233233 string.
234234
235235 ' hello'->trim; # 'hello'
236 '*+* hello *+*'->trim("*+"); # ' hello '
236 '*+* hello *+*'->trim("*+"); # ' hello '
237237 ' *+* hello *+*'->trim("*+"); # ' *+* hello'
238238
239239 =head4 ltrim
286286 C<center()> will never truncate C<$string>. If $length is less
287287 than C<< $string->length >> it will just return C<$string>.
288288
289 say "Hello"->center(4); # "Hello";
289 say "Hello"->center(4); # "Hello";
290290
291291 =head4 qx
292292
329329 my $string = "the cat sat on the mat";
330330 $string->s( qr/cat/, "dog" );
331331 $string->say; # the dog sat on the mat
332
333 String substitution. Works similarly to C<< s/// >>.
332
333 String substitution. Works similarly to C<< s/// >>.
334334 In boolean context, it returns true/false to indicate whether the substitution succeeded. C<if>, C<?:>, C<!>, and so on, all provide boolean context.
335335 It either fails or succeeds, having replaced only one occurance on success -- it doesn't replace globally.
336336 In scalar context other than boolean context, it returns the modified string (incompatible change, new as of v 1.31).
368368
369369 $string->print;
370370
371 Prints a string or a list of strings. Returns true if successful.
371 Prints a string or a list of strings. Returns true if successful.
372372
373373 =head4 say
374374
382382
383383 =head4 and
384384
385 C<and> corresponds to C<&&>. Returns true if both operands are true.
385 C<and> corresponds to C<&&>. Returns true if both operands are true.
386386
387387 if( $a->and($b) ) {
388388 ...
541541 L<bless|perlfunc/bless>, L<tie|perlfunc/tie>, L<tied|perlfunc/tied>,
542542 L<ref|perlfunc/ref>, L<grep|perlfunc/grep>, L<map|perlfunc/map>,
543543 L<join|perlfunc/join>, L<reverse|perlfunc/reverse>, and
544 L<sort|perlfunc/sort>, L<each|perlfunc/each>.
544 L<sort|perlfunc/sort>, L<each|perlfunc/each>.
545545
546546 As well as:
547547
555555
556556 =head4 uniq
557557
558 Removes all duplicate elements from an array and returns the new array
558 Removes all duplicate elements from an array and returns the new array
559559 with no duplicates.
560560
561561 my @array = qw( 1 1 2 3 3 6 6 );
690690
691691 =head4 tail
692692
693 Returns all but the first element from C<@list>.
693 Returns all but the first element from C<@list>.
694694
695695 my @list = qw(foo bar baz quux);
696696 my @rest = @list->tail; # [ 'bar', 'baz', 'quux' ]
806806 print $_[0], ' is ', $hash{$_[0]}, "\n";
807807 });
808808
809 =head4 lock_keys
809 =head4 lock_keys
810810
811811 %hash->lock_keys;
812812
854854 Methods which work on code references.
855855
856856 These are simple wrappers around the Perl core functions.
857 L<bless|perlfunc/bless>, L<ref|perlfunc/ref>,
857 L<bless|perlfunc/bless>, L<ref|perlfunc/ref>,
858858
859859 Due to Perl's precedence rules, some autoboxed literals may need to be
860860 parenthesized. For instance, this works:
891891
892892 =over 4
893893
894 =item *
894 =item *
895895
896896 File and socket operations are already implemented in an object-oriented
897897 fashion care of L<IO::Handle>, L<IO::Socket::INET>, and L<IO::Any>.
898898
899899 =item *
900900
901 Functions listed in the L<perlfunc> headings
901 Functions listed in the L<perlfunc> headings
902902
903903 =over 4
904904
946946
947947 =item *
948948
949 (Most) binary operators
949 (Most) binary operators
950950
951951 =back
952952
994994 This is a more Perl 6 way of doing things.
995995
996996 # Perl 6 - autoboxing associates classes with primitives types:
997
997
998998 print 4.sqrt, "\n";
999999
10001000 print [ 1 .. 20 ].elems, "\n";
13041304 sub m { my @ms = $_[0] =~ m{$_[1]} ; return @ms ? \@ms : undef }
13051305 sub nm { my @ms = $_[0] =~ m{$_[1]} ; return @ms ? undef : \@ms }
13061306 sub split { wantarray ? split $_[1], $_[0] : [ split $_[1], $_[0] ] }
1307 sub s {
1308 my $success = ( $_[0] =~ s{$_[1]}{$_[2]} ) ? 1 : 0;
1307 sub s {
1308 my $success = ( $_[0] =~ s{$_[1]}{$_[2]} ) ? 1 : 0;
13091309 if (Want::want('LIST')) {
13101310 Want::rreturn ($_[0]);
13111311 } elsif (Want::want('BOOL')) { # this needs to happen before the SCALAR context test
55 is "Hello, World\n"->uc, "HELLO, WORLD\n";
66
77 my @list = (1, 5, 9, 2, 0, 4, 2, 1);
8 is_deeply [@list->sort->reverse], [9,5,4,2,2,1,1,0];
8 is_deeply [@list->sort->reverse], [9,5,4,2,2,1,1,0];
99
1010 # works with references too!
1111 my $list = [1, 5, 9, 2, 0, 4, 2, 1];
2020 is [10, 20, 30, 40, 50]->pop, 50;
2121 is [10, 20, 30, 40, 50]->shift, 10;
2222
23 my $lala = "Lalalalala\n";
23 my $lala = "Lalalalala\n";
2424 is "chomp: "->concat($lala->chomp, " ", $lala), "chomp: 1 Lalalalala";
2525
2626 my $hashref = { foo => 10, bar => 20, baz => 30, qux => 40 };