added some of uri's utility actions for build script
[urisagit/Stem.git] / lib / Stem / File.pm
1 #  File: Stem/File.pm
2
3 #  This file is part of Stem.
4 #  Copyright (C) 1999, 2000, 2001 Stem Systems, Inc.
5
6 #  Stem is free software; you can redistribute it and/or modify
7 #  it under the terms of the GNU General Public License as published by
8 #  the Free Software Foundation; either version 2 of the License, or
9 #  (at your option) any later version.
10
11 #  Stem is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #  GNU General Public License for more details.
15
16 #  You should have received a copy of the GNU General Public License
17 #  along with Stem; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20 #  For a license to use the Stem under conditions other than those
21 #  described here, to purchase support for this software, or to purchase a
22 #  commercial warranty contract, please contact Stem Systems at:
23
24 #       Stem Systems, Inc.              781-643-7504
25 #       79 Everett St.                  info@stemsystems.com
26 #       Arlington, MA 02474
27 #       USA
28
29 package Stem::File ;
30
31 use strict ;
32
33 my $attr_spec = [
34
35         {
36                 'name'          => 'path',
37                 'required'      => 1,
38                 'help'          => <<HELP,
39 This is just the path to the file. Given Unix conventions, the path
40 may include the full file name from the root.  It's required.
41 HELP
42         },
43
44         {
45                 'name'          => 'mode',
46                 'default'       => 'read',
47                 'help'          => <<HELP,
48 Can be read (default), write, or read/write.  Indicates how the file
49 is to be opened using Unix conventions.
50 HELP
51         },
52
53 ] ;
54
55
56 sub new {
57
58         my( $class ) = shift ;
59
60         my $self = Stem::Class::parse_args( $attr_spec, @_ ) ;
61         return $self unless ref $self ;
62
63         return $self ;
64 }
65
66
67 sub msg_in {
68
69         my( $self, $msg ) = @_ ;
70
71         my $type = $msg->type() ;
72
73 #print $msg->dump( 'switch' ) ;
74
75         if ( $type eq 'cmd' ) {
76
77                 $self->cmd_in( $msg ) ;
78                 return ;
79         }
80 }
81
82
83 sub read {
84
85         my( $self, $read_size_wanted ) = @_ ;
86
87
88 }
89
90 sub read_line {
91
92         my( $self, $read_size_wanted ) = @_ ;
93
94         $self->{'handle'}->readline() ;
95 }
96
97 sub write {
98
99         my( $self, $write_data ) = @_ ;
100
101         $self->{'handle'}->write( $write_data ) ;
102 }
103
104 sub close {
105
106         my( $self ) = @_ ;
107
108         $self->{'handle'}->close() ;
109
110         delete( $self->{'handle'} ) ;
111 }
112
113 1 ;