Skip to content

Instantly share code, notes, and snippets.

Created January 26, 2012 13:03
Show Gist options
  • Save anonymous/1682667 to your computer and use it in GitHub Desktop.
Save anonymous/1682667 to your computer and use it in GitHub Desktop.
use v6;
class Db {
has Str $.name is rw;
has Int $.lvl is rw = 0;
has @!tb is rw;
has $!path = %*ENV<HOME>~'/.db';
method op( Str $dbname ){
if $dbname ~~ any( dir $!path ) {
@!tb = dir $!path~'/'~$dbname;
say "Database $dbname opened.";
warn "Database is empty...\n" if dir $!path~'/'~$dbname;
return self.new( :name($dbname), :lvl(0) );
} else {
say "Warning: there is not database named $dbname\nYou should use .create\n";
return 0;
}
}
}
my $obj = Db.op('test');
say $obj.name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment