Created
October 5, 2011 12:11
-
-
Save riywo/1264300 to your computer and use it in GitHub Desktop.
perlで別のモジュールのメソッドを生やす
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Fuga; | |
use strict; | |
use warnings; | |
use Hoge; | |
sub new { | |
my ($class) = @_; | |
my $self = bless {}, $class; | |
$self->{'foo'} = 'bar'; | |
return $self; | |
} | |
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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