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