Skip to content

Instantly share code, notes, and snippets.

@jerome-diver
Last active July 25, 2017 00:25
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 jerome-diver/a00c842062ce374a5ac965636d79dc37 to your computer and use it in GitHub Desktop.
Save jerome-diver/a00c842062ce374a5ac965636d79dc37 to your computer and use it in GitHub Desktop.
cannot import symbol EXPORT from add, because it already exists in this lexical scope
#--datas.pm---
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 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"}; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment