#!/usr/bin/perl use strict; main(); use YAML; sub main { my $hooks; foreach my $pkg (@ARGV) { my $rel = check_hook($pkg); if (scalar(@{$rel->{hook}}) > 0) { push(@{$hooks->{$_}}, $rel->{name}) for @{$rel->{hook}}; } } # print Dump($hooks); my @order = qw/ subscription.load customfeed.handle aggregator.filter.feed aggregator.entry.fixup aggregator.finalize update.entry.fixup update.feed.fixup update.fixup smartfeed.init smartfeed.entry smartfeed.feed smartfeed.finalize publish.init publish.entry.fixup publish.feed publish.entry publish.finalize /; foreach my $hook (@order) { print "$hook\n"; print "- $_\n" for @{$hooks->{$hook}}; print "\n"; } } sub check_hook { my $file = shift; my $name = extract_name($file); local $/; open my $fh, $file or die "$file: $!"; my $buf = <$fh>; close $fh; my @hook; if ($buf =~ m!register_hook\s*\((.*?)\)\s*(;|\})!s) { my $hooks = $1; @hook = ($hooks =~ /'([a-z\.]*)'\s*=>/g); } return { name => $name, hook => \@hook, }; } sub extract_name { my $file = shift; open my $fh, $file or die "$file: $!"; while (<$fh>) { /^package\s*Plagger::Plugin::(.*?)\s*;/ and return $1; } close $fh; die "no pkgname for $file"; }