Tagging trunk at r29452 so that the noautopack can later be synched to it.
[parrot.git] / tools / util / crow.pir
blobc91c2f1c69bb401431398d002824e317f88a5abb
1 #! ./parrot
2 # Copyright (C) 2007-2008, The Perl Foundation.
3 # $Id$
5 =head1 TITLE
7 crow.pir -- Make noise about the new Parrot release
9 =head1 DESCRIPTION
11 This utility is used to help Release Managers format announcement messages.
12 It uses a *very* simple and fast templating system, described in the related
13 module, L<runtime/parrot/library/Crow.pir>.
15 =head1 SYNOPSIS
17   # see
18   % parrot tools/util/crow.pir --help
20 =cut
23 .sub 'main' :main
24     .param pmc    args
26     load_bytecode 'Crow.pir' # TODO s/pir/pbc/
28     .local pmc exports, curr_namespace, test_namespace
29     curr_namespace = get_namespace
30     test_namespace = get_namespace ['Crow']
31     exports = split ' ', 'get_news get_args process'
32     test_namespace.export_to(curr_namespace, exports)
34     .local pmc opts
35     opts = get_args(args)
37     unless null opts goto got_opts
38     opts = new 'Hash'
39   got_opts:
41     .local pmc templates
42     templates = 'get_json'('tools/util/templates.json')
44     .local string template, type
45     type = opts['type']
46     'infix://='(type, 'text')
48     template = 'get_template'(templates, type)
50     .local pmc data
51     data = 'get_json'('tools/util/release.json')
53     .local string version
54     version = data['release.version']
56     $S0 = concat type, '.news'
57     $I0 = templates[$S0]
58     if $I0 goto get_news
59     data['NEWS'] = ''
60     goto process
61   get_news:
62     $S0 = 'get_news'(version)
63     data['NEWS'] = $S0
66   process:
67     .local string result
68     result = process(template, data)
69     say result
70 .end
73 .sub 'get_json'
74     .param string filename
76     load_bytecode 'Config/JSON.pir'
78      .local pmc exports, curr_namespace, test_namespace
79     curr_namespace = get_namespace
80     test_namespace = get_namespace [ 'Config';'JSON' ]
81     exports = split ' ', 'ReadConfig'
82     test_namespace.export_to(curr_namespace, exports)
84     .local pmc result
85     result = ReadConfig(filename)
87     .return (result)
88 .end
91 .sub 'get_template'
92     .param pmc templates
93     .param string type
95     $S0 = concat type, '.text'
96     $S1 = templates[$S0]
97     .return ($S1)
98 .end
101 .sub 'infix://='
102     .param pmc    a
103     .param pmc    b
105     if null a goto agg_undefined
106     $I0 = defined a
107     if $I0 goto return
108     assign a, b
110   return:
111     .return ()
113   agg_undefined:
114     $P0 = new 'Exception'
115     $P0['_message'] = "cannot assign to Null PMC!"
116     throw $P0
117 .end
120 # Local Variables:
121 #   mode: pir
122 #   fill-column: 100
123 # End:
124 # vim: expandtab shiftwidth=4 ft=pir: