File Coverage

blib/lib/App/VTide/Sessions.pm
Criterion Covered Total %
statement 27 36 75.0
branch n/a
condition 0 2 0.0
subroutine 9 11 81.8
pod 0 2 0.0
total 36 51 70.5


line stmt bran cond sub pod time code
1             package App::VTide::Sessions;
2              
3             # Created on: 2016-01-28 09:58:07
4             # Create by: Ivan Wills
5             # $Id$
6             # $Revision$, $HeadURL$, $Date$
7             # $Revision$, $Source$, $Date$
8              
9 1     1   7 use Moo;
  1         3  
  1         5  
10 1     1   2441 use warnings;
  1         2  
  1         25  
11 1     1   5 use version;
  1         2  
  1         5  
12 1     1   57 use Carp;
  1         3  
  1         48  
13 1     1   5 use English qw/ -no_match_vars /;
  1         2  
  1         6  
14 1     1   336 use Getopt::Alt;
  1         3  
  1         13  
15 1     1   3909 use App::VTide::Config;
  1         3  
  1         22  
16 1     1   4 use Path::Tiny;
  1         3  
  1         55  
17 1     1   7 use YAML::Syck qw/ LoadFile DumpFile /;
  1         1  
  1         412  
18              
19             our $VERSION = version->new('0.1.20');
20              
21             has sessions_file => (
22             is => 'rw',
23             lazy => 1,
24             default => sub {
25             if ( $ENV{VTIDE_DIR} && -d $ENV{VTIDE_DIR} ) {
26             mkdir path $ENV{VTIDE_DIR}, '.vtide'
27             if !-d path $ENV{VTIDE_DIR}, '.vtide';
28             return path $ENV{VTIDE_DIR}, '.vtide/sessions.yml';
29             }
30              
31             mkdir path $ENV{HOME}, '.vtide' if !-d path $ENV{HOME}, '.vtide';
32             return path $ENV{HOME}, '.vtide/sessions.yml';
33             },
34             );
35              
36             has sessions => (
37             is => 'rw',
38             lazy => 1,
39             default => sub {
40             my ($self) = @_;
41             my $file = $self->sessions_file;
42             if ( -f $file ) {
43             return LoadFile($file);
44             }
45              
46             return {};
47             }
48             );
49              
50             sub add_session {
51 0     0 0   my ( $self, @session ) = @_;
52 0           my $sessions = $self->sessions;
53 0   0       $sessions->{current} ||= [];
54 0           push @{ $sessions->{current} }, \@session;
  0            
55 0           $self->write_session();
56             }
57              
58             sub write_session {
59 0     0 0   my ($self) = @_;
60 0           my $file = $self->sessions_file;
61 0           DumpFile $file, $self->sessions;
62             }
63              
64             1;
65              
66             __END__
67              
68             =head1 NAME
69              
70             App::VTide::Sessions - Manage start and edit session
71              
72             =head1 VERSION
73              
74             This documentation refers to App::VTide::Sessions version 0.1.20
75              
76             =head1 SYNOPSIS
77              
78             use App::VTide::Sessions;
79              
80             # Brief but working code example(s) here showing the most common usage(s)
81             # This section will be as far as many users bother reading, so make it as
82             # educational and exemplary as possible.
83              
84             =head1 DESCRIPTION
85              
86             This module provides the basis from running user defined hooks. Those hooks
87             are located in the C<~/.vtide/hooks.pl> and C<$PROJECT/.vtide/hooks.pl> files.
88             They are perl files that are expected to return a hash where the keys are the
89             hook names and the values are subs to be run. Details about individual hooks
90             can be found in the various sub-command modules.
91              
92             =head1 SUBROUTINES/METHODS
93              
94             =head2 C<run ( $hook, @args )>
95              
96             The the hook C<$hook> with the supplied arguments.
97              
98             =head1 ATTRIBUTES
99              
100             =head2 vtide
101              
102             Reference to the vtide object
103              
104             =head2 hook_cmds
105              
106             Hash of configured hook subroutines
107              
108             =head1 DIAGNOSTICS
109              
110             =head1 CONFIGURATION AND ENVIRONMENT
111              
112             =head1 DEPENDENCIES
113              
114             =head1 INCOMPATIBILITIES
115              
116             =head1 BUGS AND LIMITATIONS
117              
118             There are no known bugs in this module.
119              
120             Please report problems to Ivan Wills (ivan.wills@gmail.com).
121              
122             Patches are welcome.
123              
124             =head1 AUTHOR
125              
126             Ivan Wills - (ivan.wills@gmail.com)
127              
128             =head1 LICENSE AND COPYRIGHT
129              
130             Copyright (c) 2016 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077).
131             All rights reserved.
132              
133             This module is free software; you can redistribute it and/or modify it under
134             the same terms as Perl itself. See L<perlartistic>. This program is
135             distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
136             without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
137             PARTICULAR PURPOSE.
138              
139             =cut