Skip to content

Instantly share code, notes, and snippets.

@riywo
Created October 5, 2011 12:11
Show Gist options
  • Save riywo/1264300 to your computer and use it in GitHub Desktop.
Save riywo/1264300 to your computer and use it in GitHub Desktop.
perlで別のモジュールのメソッドを生やす
package Fuga;
use strict;
use warnings;
use Hoge;
sub new {
my ($class) = @_;
my $self = bless {}, $class;
$self->{'foo'} = 'bar';
return $self;
}
1;
package Hoge;
use strict;
use warnings;
use Sub::Install;
#no strict 'refs';
#*{"Fuga::hoge"} = \&hoge;
Sub::Install::install_sub(
{
code => \&hoge,
into => "Fuga",
as => "hoge",
}
);
sub hoge {
my $c = shift;
print $c->{'foo'} . "\n";
}
1;
package Hoge2;
use strict;
use warnings;
use Exporter;
our @ISA = qw/Exporter/;
our @EXPORT = qw/hoge/;
sub hoge {
my $c = shift;
print $c->{'foo'} . "\n";
}
1;
use strict;
use warnings;
use Fuga;
my $fuga = Fuga->new;
$fuga->hoge;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment