File Coverage

blib/lib/App/Greple/type.pm
Criterion Covered Total %
statement 8 17 47.0
branch 0 6 0.0
condition n/a
subroutine 3 6 50.0
pod 0 3 0.0
total 11 32 34.3


line stmt bran cond sub pod time code
1             =encoding utf-8
2              
3             =head1 NAME
4              
5             App::Greple::type - file type filter module for greple
6              
7             =head1 SYNOPSIS
8              
9             greple -Mdig -Mtype --type-xxxx ... --dig .
10              
11             =head1 VERSION
12              
13             Version 1.01
14              
15             =head1 DESCRIPTION
16              
17             This module filters search target files by given rule. It is
18             convenient to use with other B module which support recursive
19             or multi-file search such as B<-Mfind>, B<-Mdig> or B<-Mgit>.
20              
21             For example, option for Perl is defined as this:
22              
23             option --type-perl \
24             --suffix=pl,PL,pm,pod,t,psgi \
25             --shebang=perl
26              
27             Using this option, only files those name end with B<--suffix> option
28             or files which contains string C in the first C<#!> (shebang)
29             line will be searched.
30              
31             Option B<--suffix> and B<--shebang> are defined in
32             L module.
33              
34             =head1 SHORT NAME
35              
36             Calling module as B<-Mtype::config(short)> or B<-Mtype::config=short>
37             introduce short name for rule options. When short name mode is
38             activated, all B<--type-xxxx> options can be used as B<--xxxx> as
39             well.
40              
41             =head1 OPTIONS
42              
43             option --type-actionscript --suffix=as,mxml
44             option --type-ada --suffix=ada,adb,ads
45             option --type-asm --suffix=asm,s
46             option --type-asp --suffix=asp
47             option --type-aspx --suffix=master,ascx,asmx,aspx,svc
48             option --type-batch --suffix=bat,cmd
49             option --type-cc --suffix=c,h,xs
50             option --type-cfmx --suffix=cfc,cfm,cfml
51             option --type-clojure --suffix=clj
52             option --type-cmake --suffix=cmake --select-name=^CMakeLists.txt$
53             option --type-coffeescript --suffix=coffee
54             option --type-cpp --suffix=cpp,cc,cxx,m,hpp,hh,h,hxx,c++,h++
55             option --type-csharp --suffix=cs
56             option --type-css --suffix=css
57             option --type-dart --suffix=dart
58             option --type-delphi --suffix=pas,int,dfm,nfm,dof,dpk,dproj,groupproj,bdsgroup,bdsproj
59             option --type-elisp --suffix=el
60             option --type-elixir --suffix=ex,exs
61             option --type-erlang --suffix=erl,hrl
62             option --type-fortran --suffix=f,f77,f90,f95,f03,for,ftn,fpp
63             option --type-go --suffix=go
64             option --type-groovy --suffix=groovy,gtmpl,gpp,grunit,gradle
65             option --type-haskell --suffix=hs,lhs
66             option --type-hh --suffix=h
67             option --type-html --suffix=htm,html
68             option --type-java --suffix=java,properties
69             option --type-js --suffix=js
70             option --type-json --suffix=json
71             option --type-jsp --suffix=jsp,jspx,jhtm,jhtml
72             option --type-less --suffix=less
73             option --type-lisp --suffix=lisp,lsp
74             option --type-lua --suffix=lua --shebng=lua
75             option --type-markdown --suffix=md
76             option --type-md --type-markdown
77             option --type-make --suffix=mak,mk --select-name=^(GNUmakefile|Makefile|makefile)$
78             option --type-matlab --suffix=m
79             option --type-objc --suffix=m,h
80             option --type-objcpp --suffix=mm,h
81             option --type-ocaml --suffix=ml,mli
82             option --type-parrot --suffix=pir,pasm,pmc,ops,pod,pg,tg
83             option --type-perl --suffix=pl,PL,pm,pod,t,psgi --shebang=perl
84             option --type-perltest --suffix=t
85             option --type-php --suffix=php,phpt,php3,php4,php5,phtml --shebang=php
86             option --type-plone --suffix=pt,cpt,metadata,cpy,py
87             option --type-python --suffix=py --shebang=python
88             option --type-rake --select-name=^Rakefile$
89             option --type-rr --suffix=R
90             option --type-ruby --suffix=rb,rhtml,rjs,rxml,erb,rake,spec \
91             --select-name=^Rakefile$ --shebang=ruby
92             option --type-rust --suffix=rs
93             option --type-sass --suffix=sass,scss
94             option --type-scala --suffix=scala
95             option --type-scheme --suffix=scm,ss
96             option --type-shell --suffix=sh,bash,csh,tcsh,ksh,zsh,fish \
97             --shebang=sh,bash,csh,tcsh,ksh,zsh,fish
98             option --type-smalltalk --suffix=st
99             option --type-sql --suffix=sql,ctl
100             option --type-tcl --suffix=tcl,itcl,itk
101             option --type-tex --suffix=tex,cls,sty
102             option --type-tt --suffix=tt,tt2,ttml
103             option --type-vb --suffix=bas,cls,frm,ctl,vb,resx
104             option --type-verilog --suffix=v,vh,sv
105             option --type-vim --suffix=vim
106             option --type-xml --suffix=xml,dtd,xsl,xslt,ent --select-data='\A.*<[?]xml'
107             option --type-yaml --suffix=yaml,yml
108              
109             =head1 BACKGROUND
110              
111             This module is inspired by L command, and original matching
112             rule is taken from it.
113              
114             Filename matching can be done with B<-Mfind> module, but to know file
115             type from its content, different mechanism was required. So I made
116             the B<--begin> function can die to stop the file processing, and
117             introduced new B<-Mselect> module.
118              
119             =head1 SEE ALSO
120              
121             L, L
122              
123             L
124              
125             =head1 AUTHOR
126              
127             Kazumasa Utashiro
128              
129             =head1 LICENSE
130              
131             Copyright 2021-2023 Kazumasa Utashiro.
132              
133             This library is free software; you can redistribute it and/or modify
134             it under the same terms as Perl itself.
135              
136             =cut
137              
138             package App::Greple::type;
139             our $VERSION = "1.01";
140              
141 1     1   620 use v5.14;
  1         3  
142 1     1   5 use warnings;
  1         1  
  1         21  
143 1     1   472 use Data::Dumper;
  1         5414  
  1         181  
144              
145             my($module, $argv);
146             my %opt;
147              
148             sub initialize {
149 0     0 0   ($module, $argv) = @_;
150             }
151              
152             sub config {
153 0     0 0   while (my($k, $v) = splice @_, 0, 2) {
154 0           $opt{$k} = $v;
155             }
156             }
157              
158             sub finalize {
159 0 0   0 0   if ($opt{short}) {
160 0           my @options = $module->options;
161 0           for my $opt (@options) {
162 0 0         $opt =~ /^--type-(.+)/ or next;
163 0           $module->setopt("--$1", $opt);
164             }
165             }
166 0 0         warn Dumper $module if $opt{dump};
167             }
168              
169             1;
170              
171             __DATA__