Skip to content

Instantly share code, notes, and snippets.

@zengargoyle
Created July 25, 2017 00:50
Show Gist options
  • Save zengargoyle/20e1bcf9e8cb41a56e2334b462701ca9 to your computer and use it in GitHub Desktop.
Save zengargoyle/20e1bcf9e8cb41a56e2334b462701ca9 to your computer and use it in GitHub Desktop.
my way
use YAML;
class datas {
has Str $.filename is rw;
has Array @.datas;
has Str $.directory = %*ENV<HOME> ~ "/.vim/installer";
has Str $.repo_dir = %*ENV<HOME> ~ "/.vim/bundle";
has Str $.full_filename;
# method new (Str $filename) {
# self.bless( :$filename, :@datas, :$directory, :$repo_dir, :$full_filename );
# self.initialize_directory();
# self.initialize_filename_data();
# my $thing = slurp self.full_filename;
# self.datas = load($thing);
# return self;
# }
method new($filename) {
return self.bless: filename => $filename;
}
method TWEAK {
self.initialize_directory();
self.initialize_filename_data();
my $thing = slurp self.full_filename;
# self.datas = load($thing);
}
method initialize_directory() {
unless $!directory.IO.d { mkdir $!directory or die "unable to create directory"; }
}
method initialize_filename_data() {
$!full_filename = $!directory ~ $!filename;
unless $!full_filename.IO.f {
my @default = ( { group => "default", repos => [ { url => "", title => "" } ] } );
spurt $!full_filename, dump( @default );
}
}
method save {
spurt $!full_filename, dump(@!datas) or die "can not save datas.yml";
say "Datas has been saved.";
}
method add_group( $group_name){
@!datas.push: { group => "$group_name", repos => [] };
}
has method add_repo($group_name, $title, $url) {
@!datas.map: {
if ( $_<group> eq $group_name ) {
$_<repos>.push: { title => "$title", url => "$url"}; }
}
}
}
say datas.new('myfile').perl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment