Fuse::Class - Base clsas for Fuse module implementation using class.


Fuse-Class documentation Contained in the Fuse-Class distribution.

Index


Code Index:

NAME

Top

Fuse::Class - Base clsas for Fuse module implementation using class.

VERSION

Top

Version 0.01

SYNOPSIS

Top

Fuse::Class is just a abstract class. First, you must write subclass overriding methods like named 'getattr'. (callbacks defined in Fuse)

Subclass will be written like following:

    package SampleFS;

    use base qw(Fuse::Class);

    sub getattr {
        my $self = shift; # instance or class is passed as first argment.
        my ($fname) = @_; # same as Fuse.

        ...

        return @attr; # same as Fuse.
    }
        ...

To mount your filesystem:

   use SampleFS;

   my $fuse = SampleFS->new("your", "parameters", "here");
   $fuse->main(mountpoint => '/mnt/sample', mountopts => "allow_other");




DESCRIPTION

Top

This module supports writing Fuse callback as method. Method name is same as Fuse callback, but first argment is object.

This is a small change for Fuse, but you can use power of OO like inheritance, encapsulation, ...

Exception handling:

Return value will be treated as errno in Fuse way, but you can use exception, too. If exception is thrown in your method (die is called), $! will be used as errno to notify error to Fuse.

EXPORT

Top

Nothing.

FUNCTIONS

Top

main

Same as defined in Fuse::main.

new

Create a new instance.

getattr

Same as Fuse.

getdir

Same as Fuse.

mknod

Same as Fuse.

mkdir

Same as Fuse.

rmdir

Same as Fuse.

rename

Same as Fuse.

statfs

Same as Fuse. By default implementation, returns -ENOANO. You can leave this method if your FS does not have statfs.

flush

Same as Fuse. By default implementation, returns 0. You can leave this method if your FS does not have flush.

release

Same as Fuse. By default implementation, returns 0. You can leave this method if your FS does not need anything when releaing.

fsync

Same as Fuse. By default implementation, returns 0. You can leave this method if your FS does not have fsync.

getxattr

Same as Fuse. By default implementation, returns 0. You can leave this method if your FS does not have any extended attrs.

listxattr

Same as Fuse. By default implementation, returns 0. You can leave this method if your FS does not have any extended attrs.

removexattr

Same as Fuse. By default implementation, returns 0. You can leave this method if your FS does not have any extended attrs.

setxattr

Same as Fuse. By default implementation, returns -ENOATTR. You can leave this method if your FS does not have any extended attrs.

AUTHOR

Top

Toshimitsu FUJIWARA, <tttfjw at gmail.com>

BUGS

Top

Threading is not tested.

COPYRIGHT & LICENSE

Top

SEE ALSO

Top

Fuse


Fuse-Class documentation Contained in the Fuse-Class distribution.
#
# Fuse::Class
#
# For implementation using class.
#

package Fuse::Class;

use warnings;
use strict;

our $VERSION = '0.01';

use Fuse;
use Errno;

# instance calling main
use vars qw($_Module);

my @callback;

sub main {
    my $class = shift;
    my %attr = @_;

    my @args;
    for my $opt (qw(debug mountpoint mountopts)) {
	push(@args, $opt, $attr{$opt}) if (defined($attr{$opt}));
    }

    local $_Module = $class;

    Fuse::main(@args,
	       map {$_ => __PACKAGE__ . "::_$_"} @callback);
}

BEGIN {
    @callback = qw (getattr readlink getdir mknod mkdir unlink
		    rmdir symlink rename link chmod chown truncate
		    utime open read write statfs flush release fsync
		    setxattr getxattr listxattr removexattr);

    no strict "refs";
    for my $m (@callback) {
	my $method = __PACKAGE__ . "::_$m";

	*$method = sub {
	    my $method_name = $m;

	    if ($_Module->can($method_name)) {
		my @ret = eval {
		    $_Module->$m(@_);
		};
		if ($@) {
		  return $! ? -$! : -Errno::EPERM();
		}
		else {
		  return (wantarray() ? @ret : $ret[0]);
		}
	    }
	    else {
		return -Errno::EPERM();
	    }
	}
    }
}


#
# for your convenience.
#
sub new {
    my $class = shift;
    bless {}, $class;
}

sub readlink {
    return -Errno::ENOENT();
}

sub statfs {
    return -Errno::ENOANO();
}


sub flush {
    return 0;
}

sub release {
    return 0;
}

sub fsync {
    return 0;
}

sub getxattr {
    return 0;
}

sub listxattr {
    return 0;
}

sub removexattr {
    return 0;
}

sub setxattr {
    return -Errno::EOPNOTSUPP();
}


1; # End of xxx