Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SandBox
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
PotatoGim
SandBox
Commits
3e22da84
Commit
3e22da84
authored
Jan 22, 2015
by
PotatoGim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MooseX::NonMoose를 메타 클래스에 적용하는 예
parent
0d8f3267
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
156 additions
and
0 deletions
+156
-0
moosex_nonmoose_with_meta.pl
Perl/Moose/Meta/moosex_nonmoose_with_meta.pl
+156
-0
No files found.
Perl/Moose/Meta/moosex_nonmoose_with_meta.pl
0 → 100644
View file @
3e22da84
#!/usr/bin/env perl
#=============================================================================
# FILE: moosex_nonmoose_with_meta.pl
# USAGE: ./moosex_nonmoose_with_meta.pl
# OPTIONS:
# BRIEF: 메타 클래스에 MooseX::NonMoose를 적용하는 예
# AUTHOR: Ji-Hyeon Gim <potatogim@potatogim.net>
# DATE: 01/21/2015 09:16:18 PM
# VERSION: 1.0
# LICENSE: Artistic License
# NOTE:
#=============================================================================
package
Fruits
;
sub
new
{
print
"new: "
,
__PACKAGE__
,
"\n"
;
my
$class
=
shift
;
my
$self
=
shift
;
$self
=
{}
unless
$self
&&
ref
(
$self
)
eq
"HASH"
;
bless
(
$self
,
$class
);
return
$self
;
}
sub
grow
{
print
"growing...\n"
;
}
sub
DESTROY
{
print
"DESTROY: "
,
__PACKAGE__
,
"\n"
;
}
package
main
;
use
Moose
;
use
Moose::Meta::
Class
;
use
Data::
Dumper
;
sub
new_fruit_instance
{
my
$name
=
shift
;
my
$metaclass
=
Moose::Meta::
Class
->
create
(
$name
);
$metaclass
=
Moose::Util::MetaRole::
apply_metaroles
(
for
=>
$name
,
class_metaroles
=>
{
class
=>
[
"MooseX::NonMoose::Meta::Role::Class"
],
constructor
=>
[
"MooseX::NonMoose::Meta::Role::Constructor"
],
},
);
$metaclass
->
superclasses
(
"Fruits"
);
$metaclass
->
add_attribute
(
"name"
=>
(
is
=>
"ro"
));
$metaclass
->
add_method
(
"be_split"
=>
sub
{
printf
"%s says 'I was split in half!'.\n"
,
shift
->
meta
->
name
;
}
);
$metaclass
->
add_method
(
"BUILD"
=>
sub
{
print
"BUILD: "
,
shift
->
meta
->
name
,
"\n"
;
}
);
$metaclass
->
add_method
(
"DEMOLISH"
=>
sub
{
print
"DEMOLISH: "
,
shift
->
meta
->
name
,
"\n"
;
}
);
$metaclass
->
add_method
(
"FOREIGNBUILDARGS"
=>
sub
{
my
$class
=
shift
;
my
$name
=
shift
;
print
"FOREIGNBUILDARGS: "
,
$class
,
"\n"
;
return
$name
;
}
);
my
$instance
=
$metaclass
->
name
->
new
();
return
$instance
;
}
my
$apple
=
new_fruit_instance
(
"Apple"
);
$apple
->
be_split
();
my
$banana
=
new_fruit_instance
(
"Banana"
);
$banana
->
be_split
();
my
$cherry
=
new_fruit_instance
(
"Cherry"
);
$cherry
->
be_split
();
my
$durian
=
new_fruit_instance
(
"Durian"
);
$durian
->
be_split
();
1
;
__END__
=encoding utf8
=head1 NAME
moosex_nonmoose_with_meta.pl
=head1 SYNOPSIS
메타 클래스에 MooseX::NonMoose를 적용하는 예
=head1 DESCRIPTION
=over
=item B<Item 1>
=item B<Item 2>
=item B<Item 3>
=back
=head1 AUTHOR
Ji-Hyeon Gim <potatogim@potatogim.net>
=head1 CONTRIBUTORS
=head1 COPYRIGHT AND LICENSE
Copyright(c) 2015 by Ji-Hyeon Gim <potatogim@potatogim.net>
This is free software; you can redistribute it and/or modify it
under the same terms as Perl 5 itself at:
L<http://www.perlfoundation.org/artistic_license_2_0>
You may obtain a copy of the full license at:
L<http://www.perl.com/perl/misc/Artistic.html>
=head1 SEE ALSO
=cut
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment