| MozRepl documentation | Contained in the MozRepl distribution. |
MozRepl::Util - MozRepl utilities.
version 0.01
To canonical plugin name
To method name from plugin's class name.
Plugin's class name.
new($args) in MozRepl's search argument.
To JavaScript value from string. See Data::JavaScript::Anon.
To uri string for JavaScript.
Toru Yamaguchi, <zigorou@cpan.org>
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 2007 Toru Yamaguchi, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| 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