| 709 | |
| 710 | == AUTOLOAD == |
| 711 | * 存在しないメソッドをコールしたときに呼ばれるメソッドの定義ができる |
| 712 | {{{ |
| 713 | #!perl |
| 714 | use strict; |
| 715 | use warnings; |
| 716 | |
| 717 | package Hoge; |
| 718 | |
| 719 | our $AUTOLOAD; |
| 720 | |
| 721 | sub new { |
| 722 | return bless( {}, shift ); |
| 723 | } |
| 724 | |
| 725 | sub huge { |
| 726 | my $self = shift; |
| 727 | return "huge"; |
| 728 | } |
| 729 | |
| 730 | sub AUTOLOAD { |
| 731 | my $self = shift; |
| 732 | ( my $method = $AUTOLOAD ) =~ s/.*://g; |
| 733 | return "AUTOLOAD: $method"; |
| 734 | } |
| 735 | |
| 736 | package main; |
| 737 | |
| 738 | my $hoge = new Hoge(); |
| 739 | print $hoge->hoge(), "\n"; |
| 740 | print $hoge->huge(), "\n"; |
| 741 | }}} |
| 742 | * 実行結果 |
| 743 | {{{ |
| 744 | $ perl Hoge.pm |
| 745 | AUTOLOAD: hoge |
| 746 | huge |
| 747 | }}} |