Last active
August 29, 2015 14:06
-
-
Save ynonp/b095261efffde80d0b44 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package Critter; | |
use strict; | |
use warnings; | |
use v5.18; | |
# Critter | |
our $VERSION = '1.00'; | |
# | |
# Inheritance | |
# our @ISA = qw/Animal/; | |
my $secret_method = sub { | |
say "called from within critter"; | |
}; | |
sub new { | |
my ( $cls, $name ) = @_; | |
my $self = { | |
name => $name, | |
count => 0, | |
}; | |
bless $self, $cls; | |
return $self; | |
} | |
sub hello { | |
my ( $self ) = @_; | |
say "Hello ", $self->{name}; | |
$self->{count}++; | |
} | |
sub people_met { | |
my ( $self ) = @_; | |
say $self->{count}; | |
} | |
sub DESTROY { | |
my ( $self ) = @_; | |
use Data::Dumper; | |
print Dumper($self); | |
say "this is called just before the object is destroyed"; | |
} | |
1; | |
This file contains hidden or 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
package Hello; | |
use strict; | |
use warnings; | |
sub bye { | |
print "goodbye cruel world\n"; | |
} | |
sub hi { | |
bye(); | |
} | |
1; |
This file contains hidden or 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 v5.14; | |
use warnings; | |
use strict; | |
use Test::More tests => 4; | |
use MyStack; | |
MyStack::add_item(10); | |
MyStack::add_item(20); | |
MyStack::add_item(22, 33); | |
# prints 33 | |
is(MyStack::pop_item(), 33, "Pop first item"); | |
# prints 22 | |
is(MyStack::pop_item(), 22, "Pop second item"); | |
# prints 2 | |
is(MyStack::count_items(), 2, "Item count == 2"); | |
while ( MyStack::pop_item() ) { | |
} | |
is(MyStack::count_items(), 0, "Item count == 0"); |
This file contains hidden or 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 v5.14; | |
use strict; | |
use warnings; | |
use Contacts; | |
use Test::More tests => 3; | |
use List::Util qw/first/; | |
my $home_book = Contacts::init(); | |
my $work_book = Contacts::init(); | |
Contacts::add_contact( $home_book, 'Tom', { lives_in => 'USA', email => '[email protected]' }); | |
Contacts::add_contact( $home_book, 'Bob', { lives_in => 'USA', email => '[email protected]' }); | |
Contacts::add_contact( $work_book, 'Mike', { lives_in => 'Mars', email => '[email protected]' }); | |
my @result = Contacts::contacts_by_country( $home_book, 'USA' ); | |
ok( first { $_ eq 'Tom' } @result, "Tom is in \@result"); | |
ok( first { $_ eq 'Bob' } @result, "Bob is in \@result"); | |
is( @result, 2, "Result has 2 items"); |
This file contains hidden or 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 strict; | |
use warnings; | |
use v5.18; | |
use Hello; | |
sub bye { | |
print "bye bye\n"; | |
} | |
Hello::hi(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment