| 1 |
|
| MODULE = XLog PACKAGE = XLog::Formatter |
| 2 |
|
| PROTOTYPES: DISABLE |
| 3 |
|
| |
| 4 |
|
| PerlObjectFormatter* PerlObjectFormatter::new () { |
| 5 |
1 |
| PROTO = Stash::from_name(CLASS).bless(Hash::create()); |
| 6 |
1 |
▶ | RETVAL = new PerlObjectFormatter(); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = new PerlObjectFormatter(); |
1 |
0 |
1 |
|
| 7 |
1 |
▶ | } |
Branch: 3 branches
| Branch | True | False | Total |
| } |
1 |
0 |
1 |
| } |
1 |
0 |
1 |
| } |
1 |
0 |
1 |
|
| 8 |
1 |
▶ | |
Branch: 4 branches
| Branch | True | False | Total |
|
1 |
0 |
1 |
|
1 |
0 |
1 |
|
1 |
0 |
1 |
|
0 |
0 |
0 |
|
| 9 |
|
| MODE: INLINE |
| 10 |
|
| |
| 11 |
|
| static const char* DECORATOR_KEY = "_decorator"; |
| 12 |
|
| |
| 13 |
|
| // let it be only script basename, without file |
| 14 |
|
| static string decorate_default(const char* name) { |
| 15 |
|
| string in(name); |
| 16 |
|
| auto pos = in.find_last_of("/\\"); |
| 17 |
|
| if (pos == string::npos) { |
| 18 |
|
| return in; |
| 19 |
|
| } |
| 20 |
|
| return in.substr(pos + 1); |
| 21 |
|
| } |
| 22 |
|
| |
| 23 |
|
| static xs::Sv::payload_marker_t spy_$0_marker{}; |
| 24 |
|
| |
| 25 |
|
| static int spy_$0(pTHX_ SV* sv, MAGIC* mg) { |
| 26 |
|
| if (mg->mg_virtual == &spy_$0_marker) { |
| 27 |
|
| Stash stash("XLog::Formatter::Pattern"); |
| 28 |
|
| auto decorator = stash.sub(DECORATOR_KEY); |
| 29 |
|
| string $0; |
| 30 |
|
| if (decorator) { |
| 31 |
|
| auto decorated = decorator.call(sv); |
| 32 |
|
| $0 = SvPV_nolen(decorated); |
| 33 |
|
| } |
| 34 |
|
| else { |
| 35 |
|
| $0 = decorate_default(SvPV_nolen(sv)); |
| 36 |
|
| } |
| 37 |
|
| set_program_name($0); |
| 38 |
|
| } |
| 39 |
|
| return 0; |
| 40 |
|
| } |
| 41 |
|
| |
| 42 |
|
| MODULE = XLog PACKAGE = XLog::Formatter::Pattern |
| 43 |
|
| PROTOTYPES: DISABLE |
| 44 |
|
| |
| 45 |
|
| BOOT { |
| 46 |
8 |
▶ | Stash(__PACKAGE__).inherit("XLog::IFormatter"); |
Branch: 2 branches
| Branch | True | False | Total |
| Stash(__PACKAGE__).inherit("XLog::IFormatter"); |
8 |
0 |
8 |
| Stash(__PACKAGE__).inherit("XLog::IFormatter"); |
8 |
0 |
8 |
|
| 47 |
|
| |
| 48 |
8 |
| spy_$0_marker.svt_set = spy_$0; |
| 49 |
|
| |
| 50 |
8 |
| auto $0_sv = get_sv("0", 0); |
| 51 |
|
| MAGIC* mg; |
| 52 |
8 |
| Newx(mg, 1, MAGIC); |
| 53 |
8 |
| mg->mg_moremagic = SvMAGIC($0_sv); |
| 54 |
8 |
| SvMAGIC_set($0_sv, mg); |
| 55 |
8 |
| mg->mg_virtual = const_cast<xs::Sv::payload_marker_t*>(&spy_$0_marker); |
| 56 |
8 |
| mg->mg_type = PERL_MAGIC_ext; |
| 57 |
8 |
| mg->mg_len = 0; |
| 58 |
8 |
| mg->mg_private = 0; |
| 59 |
8 |
| mg->mg_flags = 0; |
| 60 |
8 |
| mg->mg_ptr = NULL; |
| 61 |
8 |
| mg->mg_obj = NULL; |
| 62 |
|
| |
| 63 |
8 |
| auto $0 = SvPV_nolen($0_sv); |
| 64 |
8 |
▶ | set_program_name(decorate_default($0)); |
Branch: 1 branch
| Branch | True | False | Total |
| set_program_name(decorate_default($0)); |
8 |
0 |
8 |
|
| 65 |
|
| } |
| 66 |
|
| |
| 67 |
1 |
| IFormatter* PatternFormatter::new (string_view fmt) |
| 68 |
1 |
▶ | |
Branch: 1 branch
| Branch | True | False | Total |
|
1 |
0 |
1 |
|
| 69 |
1 |
▶ | void set_program_decorator(Sub callback) { |
Branch: 4 branches
| Branch | True | False | Total |
| void set_program_decorator(Sub callback) { |
1 |
0 |
1 |
| void set_program_decorator(Sub callback) { |
1 |
0 |
1 |
| void set_program_decorator(Sub callback) { |
1 |
0 |
1 |
| void set_program_decorator(Sub callback) { |
0 |
0 |
0 |
|
| 70 |
1 |
▶ | Stash stash(__PACKAGE__); |
Branch: 1 branch
| Branch | True | False | Total |
| Stash stash(__PACKAGE__); |
1 |
0 |
1 |
|
| 71 |
1 |
▶ | stash.store(DECORATOR_KEY, callback); |
Branch: 1 branch
| Branch | True | False | Total |
| stash.store(DECORATOR_KEY, callback); |
1 |
0 |
1 |
|
| 72 |
|
| } |
| 73 |
|
| |