/[VRac]/Session.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /Session.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 145 - (show annotations)
Sun Aug 5 13:27:27 2007 UTC (11 years, 10 months ago) by dpavlin
File size: 1101 byte(s)
- sessions which allows you to record your interaction with machine
- tape writer which create file on disk
- improved pod for VRac

1 package Session;
2
3 # Dobrica Pavlinusic, <dpavlin@rot13.org> 08/05/07 14:27:15 CEST
4
5 use strict;
6 use warnings;
7
8 use Carp qw/confess/;
9 use Data::Dump qw/dump/;
10 use File::Slurp;
11
12 use base qw/Class::Accessor/;
13 #__PACKAGE__->mk_accessors(qw());
14
15
16 =head1 NAME
17
18 Session - save or load emulator interactive session
19
20 =cut
21
22 =head1 FUNCTIONS
23
24 =head2 record_session
25
26 $self->record_session( 'name', $values );
27
28 =cut
29
30 my $last_tick = 0;
31
32 sub record_session {
33 my $self = shift;
34 my $name = shift || confess "no name?";
35
36 my $t = $self->app->ticks;
37 my $dt = $t - $last_tick;
38 $last_tick = $t;
39
40 $self->append_to_file('session.pl', "\$s->{$t}->{$name} = ", dump( @_ ),";\n");
41
42 }
43
44 =head2 load_session
45
46 $self->load_session( '/path/to/session.pl' );
47
48 =cut
49
50 sub load_session {
51 my $self = shift;
52 my $path = shift || confess "no path?";
53
54 my $s;
55 eval read_file( $path );
56 warn "s = ",dump( $s );
57
58 my @timeline = sort { $a <=> $b } keys %$s;
59
60 my ( $from, $to ) = @timeline[0,-1];
61 printf "loaded session %.2f-%.2fs with %d events\n", $from / 1000, $to / 1000, $#timeline + 1;
62 }
63
64 =head1 SEE ALSO
65
66 L<VRac>
67
68 =cut
69
70 1;

  ViewVC Help
Powered by ViewVC 1.1.26