Last active
July 25, 2017 00:25
cannot import symbol EXPORT from add, because it already exists in this lexical scope
This file contains 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
#--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