This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# candidate for abs() in perl6 - just not sure where it should live | |
our Num multi method abs is export { self < 0 ?? self * -1 !! self } | |
# multi abs(Num $number) { $number < 0 ?? $number * -1 !! $number } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How does one CAST from a Str to an Int in rakudo? | |
# This is an example going from an Int to a Str ... | |
multi sub f($x is rw) { | |
say 'before ' ~ $x ~ ' = ' ~ $x.WHAT; | |
$x = ~$x; | |
say 'after ' ~ $x ~ ' = ' ~ $x.WHAT; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
multi sub to_num(Str $number) returns Num { +$number } | |
my $s = "10"; | |
my $i = to_num($s); | |
say 'before: ' ~ $s.WHAT; # before: Str | |
say 'after : ' ~ $i.WHAT; # after : Num | |
=begin pod | |
=item Casting | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
perl -E 'do { say "{ $_ : " . ( -l $_ ? "Y" : "N" ) ." }" } for @ARGV' Desktop/profile.txt /usr/local/bin/perl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Test::More; | |
use MooseX::Types::Moose qw(Str); | |
# Why does this method return "undef"? | |
# Is that intentional (because it's rather counter-intuitive)? | |
ok not( Str->validate('An instance of Str') ), 'returns undef'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class Foo | |
attr_accessor :bar | |
def initialize | |
@bar = "bar" | |
yield( self ) if block_given? | |
return self | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Modern::Perl; | |
use Test::Most; | |
{ | |
package RestClient; | |
use Moose; | |
use Data::Dumper; | |
has url => ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use REST::Client; | |
use Data::Dumper; | |
use JSON; | |
my $client = | |
REST::Client->new( { host => 'http://username:password@localhost:3000' } ); | |
# Add header "Content-Type" | |
$client->addHeader( content_type => 'application/json' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use 5.10.0; | |
use warnings; | |
{ | |
package Foo; | |
use Moose; | |
local $SIG{__WARN__} = sub { }; | |
has private => ( isa => 'Int' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use MooseX::Declare; | |
role Validation { | |
requires qw/ GET HEAD responseCode responseContent /; | |
after GET { confess 'URL does not exist' if $self->responseCode eq 404 }; | |
}; | |
class App with(Validation) { | |
use Moose::Util::TypeConstraints; | |
use REST::Client; |
OlderNewer