summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-06-08 20:10:23 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-06-08 20:10:23 +0200
commitf303e11a43325cecbd03a1a465903a3e2452e432 (patch)
tree10bb66c3490dfc9ed6a9b66e30b7ed41b8addb4b
parent88010542443bf1f83906a0bbf7e3003d045471f6 (diff)
App/Raps2: Run sanity_check and load_config in new
-rwxr-xr-xbin/raps23
-rw-r--r--lib/App/Raps2.pm12
-rw-r--r--t/29-app-raps2.t7
3 files changed, 14 insertions, 8 deletions
diff --git a/bin/raps2 b/bin/raps2
index c92fe0e..54d5d3c 100755
--- a/bin/raps2
+++ b/bin/raps2
@@ -13,9 +13,6 @@ my ( $action, @args ) = @ARGV;
our $VERSION = '0.3';
-$raps2->sanity_check();
-$raps2->load_config();
-
given ($action) {
when ('add') { $raps2->cmd_add(@args) }
when ('del') { $raps2->cmd_remove(@args) }
diff --git a/lib/App/Raps2.pm b/lib/App/Raps2.pm
index 7de4b1a..6b40cc2 100644
--- a/lib/App/Raps2.pm
+++ b/lib/App/Raps2.pm
@@ -24,7 +24,14 @@ sub new {
$ref->{default} = \%conf;
- return bless( $ref, $obj );
+ bless( $ref, $obj );
+
+ if ( not $conf{dont_touch_fs} ) {
+ $ref->sanity_check();
+ $ref->load_config();
+ }
+
+ return $ref;
}
sub file_to_hash {
@@ -383,6 +390,7 @@ with its key/value pairs.
Create working directories (~/.config/raps2 and ~/.local/share/raps2, or the
respective XDG environment variable contents), if they don't exist yet.
+Automatically called by B<new>.
Calls B<create_config> if no raps2 config was found.
@@ -396,7 +404,7 @@ Creates a default config and asks the user to set a master password.
=item $raps2->load_config()
-Load config
+Load config. Automatically called by B<new>.
=item $raps2->pw()
diff --git a/t/29-app-raps2.t b/t/29-app-raps2.t
index d1f5bac..ddea7fa 100644
--- a/t/29-app-raps2.t
+++ b/t/29-app-raps2.t
@@ -8,7 +8,7 @@ use Test::More;
eval "use Test::MockObject";
plan skip_all => 'Test::MockObject required' if $@;
-plan tests => 3;
+plan tests => 4;
my $mock = Test::MockObject->new();
$mock->fake_module(
@@ -18,12 +18,13 @@ $mock->fake_module(
use_ok('App::Raps2');
-my $r2 = App::Raps2->new();
+my $r2 = App::Raps2->new( dont_touch_fs => 1 );
isa_ok($r2, 'App::Raps2');
+isa_ok($r2->ui(), 'App::Raps2::UI');
+
is_deeply(
{ $r2->file_to_hash('t/in/hash') },
{ key => 'value', otherkey => 'othervalue' },
'file_to_hash works',
);
-