File Coverage

blib/lib/POE/Devel/ProcAlike/ModuleInfo.pm
Criterion Covered Total %
statement 15 44 34.0
branch 0 4 0.0
condition n/a
subroutine 5 12 41.6
pod 1 3 33.3
total 21 63 33.3


line stmt bran cond sub pod time code
1             # Declare our package
2             package POE::Devel::ProcAlike::ModuleInfo;
3 1     1   1226 use strict; use warnings;
  1     1   2  
  1         32  
  1         5  
  1         2  
  1         29  
4              
5             # Initialize our version
6 1     1   5 use vars qw( $VERSION );
  1         1  
  1         44  
7             $VERSION = '0.02';
8              
9             # Set our superclass
10 1     1   4 use base 'Filesys::Virtual::Async::inMemory';
  1         2  
  1         85  
11              
12             # portable tools
13 1     1   5 use File::Spec;
  1         2  
  1         383  
14              
15             sub new {
16             # make sure we set a readonly filesystem!
17 0     0 1   return __PACKAGE__->SUPER::new(
18             'readonly' => 1,
19             );
20             }
21              
22             #/modules
23             # # place for modules to dump their info ( those who are aware of poe-devel-procalike )
24             #
25             # /poe-component-server-simplehttp
26             # # module name will be converted to above format
27             # # allowed only one object per module, they can stuff any data they want in their area
28             my %fs = (
29             # start with no modules loaded
30             );
31              
32             # helper sub to munge package names
33             sub _mungepkg {
34 0     0     my( $self, $pkg ) = @_;
35              
36             # change :: to -
37 0           $pkg =~ s|::|-|g;
38              
39             # lowercase everything
40 0           $pkg = lc( $pkg );
41              
42             # all done!
43 0           return $pkg;
44             }
45              
46             # adds a package
47             sub register {
48 0     0 0   my( $self, $pkg ) = @_;
49              
50             # munge the package name to our "standard" format
51 0           $pkg = $self->_mungepkg( $pkg );
52              
53             # sanity check
54 0 0         if ( exists $fs{ $pkg } ) {
55 0           return;
56             }
57              
58             # yay, we can add the package!
59 0           $fs{ $pkg } = 1;
60 0           return 1;
61             }
62              
63             # removes a package
64             sub unregister {
65 0     0 0   my( $self, $pkg ) = @_;
66              
67             # munge the package name to our "standard" format
68 0           $pkg = $self->_mungepkg( $pkg );
69              
70             # sanity check
71 0 0         if ( ! exists $fs{ $pkg } ) {
72 0           return;
73             }
74              
75             # yay, we can remove the package!
76 0           delete $fs{ $pkg };
77 0           return 1;
78             }
79              
80             # we cheat here and not implement a lot of stuff because we know the FUSE api never calls the "extra" APIs
81             # that ::Async provides. Furthermore, this is a read-only filesystem so we can skip even more APIs :)
82              
83             # _rmtree
84              
85             # _scandir
86              
87             # _move
88              
89             # _copy
90              
91             # _load
92              
93             sub _readdir {
94 0     0     my( $self, $path ) = @_;
95              
96             # return our modules
97 0           return [ keys %fs ];
98             }
99              
100             # _rmdir
101              
102             # _mkdir
103              
104             # _rename
105              
106             # _mknod
107              
108             # _unlink
109              
110             # _chmod
111              
112             # _truncate
113              
114             # _chown
115              
116             # _utime
117              
118             sub _stat {
119 0     0     my( $self, $path ) = @_;
120              
121             # return generic info
122 0           my ($atime, $ctime, $mtime, $size, $modes);
123 0           $atime = $ctime = $mtime = time();
124 0           my ($dev, $ino, $rdev, $blocks, $gid, $uid, $nlink, $blksize) = ( 0, 0, 0, 1, (split( /\s+/, $) ))[0], $>, 1, 1024 );
125 0           $size = 0;
126 0           $modes = oct( '040755' );
127              
128             # count subdirs
129 0           $nlink = 2 + scalar keys %fs;
130              
131 0           return( [ $dev, $ino, $modes, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks ] );
132             }
133              
134             # _write
135              
136             sub _open {
137 0     0     my( $self, $path ) = @_;
138              
139             # we don't have anything to open!
140 0           return;
141             }
142              
143             1;
144             __END__