MozRepl::Util - MozRepl utilities.


MozRepl documentation Contained in the MozRepl distribution.

Index


Code Index:

NAME

Top

MozRepl::Util - MozRepl utilities.

VERSION

Top

version 0.01

SYNOPSIS

Top

METHODS

Top

canonical_plugin_name($plugin)

To canonical plugin name

To method name from plugin's class name.

$plugin

Plugin's class name.

new($args) in MozRepl's search argument.

javascript_value($value)

To JavaScript value from string. See Data::JavaScript::Anon.

javascript_uri($uri)

To uri string for JavaScript.

SEE ALSO

Top

Data::JavaScript::Anon
URI, URI::file

AUTHOR

Top

Toru Yamaguchi, <zigorou@cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-mozrepl-util@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

COPYRIGHT & LICENSE

Top


MozRepl documentation Contained in the MozRepl distribution.
package MozRepl::Util;

use strict;
use warnings;

use Data::JavaScript::Anon;
use File::Spec;
use UNIVERSAL::require;
use URI;

our $VERSION = '0.01';

sub canonical_plugin_name {
    my ($class, $plugin) = @_;

    my ($abs, $canonical_plugin) = ($plugin =~ /^(\+)([^\+]+)/);

    if (!$abs && !$canonical_plugin) {
        $canonical_plugin = "MozRepl::Plugin::" . $plugin;
    }

    return $canonical_plugin;
}

sub plugin_to_method {
    my ($class, $plugin, $search) = @_;

    if ($plugin->can("method_name") && $plugin->method_name) {
        return $plugin->method_name;
    }

    my $suffix = (grep { $plugin =~ /^$_/x } @{$search})[0];

    my $plugin_name = $plugin;
    $plugin_name =~ s/^${suffix}:://;

    my $method = join("_", map { lc($_) } split(/::/, $plugin_name));

    unless ($suffix eq 'MozRepl::Plugin') {
        $method = join("_", map { lc($_) } split(/::/, $suffix)) . "_$method";
    }

    return $method;
}

sub javascript_value {
    my ($class, $value) = @_;

    return Data::JavaScript::Anon->anon_dump($value);
}

sub javascript_uri {
    my ($class, $uri) = @_;

    unless ($uri =~ m|^[a-zA-Z][a-zA-Z0-9.+\-]*:|) {
        return URI::file->new(File::Spce->rel2abs($uri))->as_string;
    }
    else {
        return URI->new($uri)->as_string;
    }
}

1; # End of MozRepl::Util