| 1 | package Sparrow::Constants; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | use base 'Exporter'; | ||
| 6 | |||
| 7 | our @EXPORT = qw { | ||
| 8 | spl_file | ||
| 9 | spi_file | ||
| 10 | spci_file | ||
| 11 | sparrow_conf_file | ||
| 12 | sparrow_root | ||
| 13 | sparrow_hub_api_url | ||
| 14 | editor | ||
| 15 | default_task_ignore_file | ||
| 16 | }; | ||
| 17 | |||
| 18 | |||
| 19 | # sparrow configuration file | ||
| 20 | |||
| 21 | sub home_dir { | ||
| 22 | |||
| 23 | $^O =~ 'MSWin' ? "C:/Users/".getlogin() : $ENV{HOME} | ||
| 24 | } | ||
| 25 | |||
| 26 | sub safe_env { | ||
| 27 | my $v = shift; | ||
| 28 | $v=~s/\s//g if $^O =~ 'MSWin'; | ||
| 29 | $v; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub sparrow_conf_file () { | ||
| 33 | $ENV{SPARROW_CONF_PATH} || do { $ENV{SPARROW_ROOT} ? safe_env("$ENV{SPARROW_ROOT}/sparrow.yaml") : safe_env(home_dir()."/sparrow.yaml") } | ||
| 34 | }; | ||
| 35 | |||
| 36 | # sparrow index - for public plugins comes from SparrowHub | ||
| 37 | sub spi_file () { safe_env($ENV{SPARROW_ROOT} ? "$ENV{SPARROW_ROOT}/sparrow.index" : home_dir()."/sparrow.index") }; | ||
| 38 | |||
| 39 | # sparrow custom index - for custom plugins comes from custom repository (see "repo" in sparrow ini file ) | ||
| 40 | sub spci_file () { safe_env($ENV{SPARROW_ROOT} ? "$ENV{SPARROW_ROOT}/sparrow.custom.index" : home_dir()."/sparrow.custom.index") }; | ||
| 41 | |||
| 42 | # sparrow list index - for private plugins comes from github repositories | ||
| 43 | sub spl_file () { safe_env($ENV{SPARROW_ROOT} ? "$ENV{SPARROW_ROOT}/sparrow.list" : home_dir()."/sparrow.list") }; | ||
| 44 | |||
| 45 | sub sparrow_root () { safe_env($ENV{SPARROW_ROOT} || home_dir()."/sparrow") }; | ||
| 46 | |||
| 47 | # SparrowHub API | ||
| 48 | sub sparrow_hub_api_url () { $ENV{sparrow_hub_api_url} || 'https://sparrowhub.org' }; | ||
| 49 | |||
| 50 | sub editor () { $ENV{'EDITOR'} }; | ||
| 51 | |||
| 52 | # default task ignore file | ||
| 53 | sub default_task_ignore_file () { safe_env(home_dir()."/task.ignore") }; | ||
| 54 | |||
| 55 | 1; |