Kang-min Liu // @gugod
LINE Fukuoka
YAPC Tokyo
Note:
…についで紹介しています
自動修復?
PPI で
コードを
変更
Perl5 code を DOM にする
$doc = PPI::Document->new('Module.pm');
$doc->prune('PPI::Token::Comment');
$doc->save('Module.pm');
# ArrarRef[ PPI::Element ] | undef
$elements = $doc->find('PPI::Token::Whitespace');
# ArrarRef[ PPI::Element ] | undef
$elements = $doc->find(sub {
$_[1]->isa('PPI::Statement::Sub')
&& $_[1]->name eq 'hoge'
});
# PPI::Element | undef
$element = $doc->find_first(sub {
$_[1]->isa('PPI::Token::Symbol')
&& $_[1]->content eq '$hoge'
});
Note:
find method で
pattern を指定して、 (指定: してい)
element objects として取得できます (取得: しゅとく)
remove
)if ($found = $doc->find(...)) {
for my $elem (@$found) {
$elem->remove;
}
}
Note:
削除 さくじょ
method call メソッド コール
insert_*
)
$new_elem = ...; # 作る
$elem = $doc->find_first(...);
$elem->insert_before( $new_elem );
$elem->insert_after( $new_elem );
Note:
付け加える = つけくわえる
挿入 = そうにゅう
my $doc2 = PPI::Document->new(\$code_str);
my @new_elems = $doc2->children;
my $e = $doc->find_first(...);
for (@new_elems) {
$_->remove; # cut
$e->insert_before($_); # paste
}
$e のまえに paste
Note:
PPI::Document::Fragement exists but
it is not really integrated with rest of PPI
$bug = $doc->find( ??? )
Critique Perl source code for best-practices.
Perl code を評価する
eval "print $foo"; # not ok
eval { print $foo }; # ok
my $foo = $baz if $bar; #not ok
my $foo = $baz unless $bar; #not ok
our $foo = $baz for @list; #not ok
local $foo = $baz foreach @list; #not ok
Find Dead code (ゴミコード)
code review は
bot がしてくれて
良いやん
Reviewdog を飼ってコードレビューや開発を改善しませんか
CI で code review しましょう
# .reviewdog.yml
runner:
perlcritic:
cmd: perlcritic --profile .perlcriticrc --verbose 1 *.psgi lib/
errorformat:
- "%f:%l:%c:%m"
name: perlcritic
Docker Image: https://hub.docker.com/r/gugod/perlcritic-reviewdog
Drone CI に使用可能
bot が
修正してくれません ?
(experimental project)
https://github.com/gugod/p5-nitpick
nits (小さいゴミ) を自動的に取り除く
Note:
取り除く: とりのぞく
do_this();;
semi-colons 多すぎ / empty statements.# A
$n = scalar @arr;
# B
$n = @arr;
# A
@a = @{[ "foo", "bar", foo() ]};
# B
@a = ("foo", "bar", foo());
$bugs = $doc->find( ... )
ご清聴
ありがとう
ございました
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing