Created
May 20, 2010 14:15
-
-
Save azurestone/407601 to your computer and use it in GitHub Desktop.
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; | |
my $name = 'hoge'; | |
my $value = 'xxxxxxx'; | |
my $json = { name => $name, value => $value }; | |
# ただのhashref | |
my $yaml = { name => $name, value => $value }; | |
my $html = { name => $name, value => $value }; | |
# $json は JSON で出したいので... | |
TestJSON::output($json); | |
# $yaml は YAML で出したいので...... | |
TestYAML::output($yaml); | |
# $html は HTML で出したいので......... | |
TestHTML::output($html); | |
# データはただのhashrefなので、それのoutputを担当するpackageは | |
# 自分でその都度選んであげるしかない。なのでめんどい。 | |
exit; | |
#----------------------------------------------------- | |
package TestJSON; | |
sub output { | |
my $self = shift; | |
printf '{ "%s" => "%s" }', $self->{name}, $self->{value}; | |
} | |
#----------------------------------------- | |
package TestYAML; | |
sub output { | |
my $self = shift; | |
printf '%s: %s', $self->{name}, $self->{value}; | |
} | |
#----------------------------------------- | |
package TestHTML; | |
sub output { | |
my $self = shift; | |
printf '<dl><dt>%s</dt><dd>%s</dd></dl>', $self->{name}, $self->{value}; | |
} | |
#------------------------------------------ | |
1; | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment