Skip to content

Instantly share code, notes, and snippets.

@ynonp
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ynonp/b095261efffde80d0b44 to your computer and use it in GitHub Desktop.
Save ynonp/b095261efffde80d0b44 to your computer and use it in GitHub Desktop.
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;
package Hello;
use strict;
use warnings;
sub bye {
print "goodbye cruel world\n";
}
sub hi {
bye();
}
1;
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");
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 => 'tomthecat@gmail.com' });
Contacts::add_contact( $home_book, 'Bob', { lives_in => 'USA', email => 'bob@gmail.com' });
Contacts::add_contact( $work_book, 'Mike', { lives_in => 'Mars', email => 'mike@gmail.com' });
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");
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